roblox
Tutorial page
This article is an easy tutorial.
Scripting
This page is a tutorial about Scripting.

In this tutorial, we are going to make a Part light iconPart dark iconPart that vanishes when touched and reappears shortly. We start by creating a part, and inserting a Script light iconScript dark iconScript into it. Your hierarchy should look like this.

Open the script, and clear all the code. The first thing we want to do is define variables. The only variable we will need for this script is a variable called 'debounce'. This tutorial will explain what this variable is for. Next, we will hook up the Touched event.

debounce=true
script.Parent.Touched:Connect(function(hit)

end)

Now we will check for a humanoid and check for the denounce.

debounce=true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and denounce == true then
        debounce=false
    end
end)

Next, we need to set up a loop which will make the part vanish after a second.

debounce=true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and denounce == true then
        debounce=false
        for i = 1,10 do
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.1)
        end
        script.Parent.CanCollide = false
    end
end)

The last step is to make it reappear. We will put a delay of 5 seconds until it reappears. Skip this step if you don't want your part to come back.

debounce=true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and denounce == true then
        debounce=false
        for i = 1,10 do
            script.Parent.Transparency = script.Parent.Transparency + 0.1
            wait(0.1)
        end
        script.Parent.CanCollide = false
        wait(5)
        script.Parent.CanCollide = true
        for i = 1,10 do
            script.Parent.Transparency = script.Parent.Transparency - 0.1
            wait(0.1)
        end
        debounce=true
    end
end)