Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make block disappear when player touched it?

Asked by 9 years ago

So when the player touches a certain block it disapears.

1 answer

Log in to vote
0
Answered by 9 years ago

When making things like this, there are various ways to do it, and I think this is the easiest and best way. Using a for loop, you can make the brick fade out, or you can just destroy it by using the :Destroy() or :Remove() events.

Keep in mind this will only work if your hierarchy is as such:

*Part *Script

Well, this is the script I have made.

01script.Parent.Touched:connect(function(hit) -- connects function with script.Parent.Touched
02    if hit.Parent.Humanoid then -- checks if it's an NPC or a player.
03        if script.Parent.Transparency < 1 then -- checks if the transparency is less than one
04            for i = 0, 1, 0.1 do
05 
06                -- somewhat intermediate method --
07 
08                script.Parent.Transparency = i --this makes it fade
09                script.Parent.CanCollide = false --this makes it so you can go through it
10 
11                wait(0.1) -- how fast the fade is, you can change this.
12            end
13            script.Parent.Destroy()
14        end
15            -- alternate method--  
16 
17        script.Parent:Destroy() -- simply destroys the brick
18    end
19end)
Ad

Answer this question