Disappearing Part

Learn how to make a part disappear when a player steps on it.

by Crazee_Monkee

Author Avatar

Introduction

Welcome! I'm Crazee_Monkee! I'm going to show you how to make a part disappear and reappear. This is a very simple tutorial, and will only require one script. I am going to assume you know how to insert objects, scripts, and parts into your game.

Getting Started

First, open up Roblox Studio. Next, insert a part into your game, and insert a script into the part. If you are using a model, you have to put the script into each individual part, not just in the model. Make sure you have Explorer and Properties open, as well as Output.

Making the Part Disappear

To make the part disappear, we have to add the function.

function OnTouch()

Next, we have to make it wait a bit to disappear after the player touches the part.

function OnTouch()
    wait(0.5)

You can make it take any amount of time to disappear you want. Now, to finish off this half of the code, we have to add what will happen after the wait, which is making the part disappear. Code always goes top to bottom.

function OnTouch()
    wait(0.5)
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false

And now your part will disappear when a player touches it!

Making the Part Reappear

If you want the part to reappear, then we have to add another wait, so that the part doesn't immediatetly reappear.

function OnTouch()
    wait(0.5)
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    wait(1)

Now, we have to add what will happen after the wait, in this case making the part reappear.

function OnTouch()
    wait(0.5)
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    wait(1)
    script.Parent.Transparency = 0
    script.Parent.CanCollide = true

Now, if the end isn't already there, we have to add it.

function OnTouch()
    wait(0.5)
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    wait(1)
    script.Parent.Transparency = 0
    script.Parent.CanCollide = true
end

Here is the last line of code you need to add:

function OnTouch()
    wait(0.5)
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    wait(1)
    script.Parent.Transparency = 0
    script.Parent.CanCollide = true
end

script.Parent.Touched:connect(OnTouch)

And now you're done! If you test the game and touch the part, it should disappear, and then reappear. If it doesn't, make sure you typed the code in correctly.

View in-game to comment, award, and more!