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.

script.Parent.Touched:connect(function(hit) -- connects function with script.Parent.Touched
    if hit.Parent.Humanoid then -- checks if it's an NPC or a player.
        if script.Parent.Transparency < 1 then -- checks if the transparency is less than one
            for i = 0, 1, 0.1 do

                -- somewhat intermediate method --

                script.Parent.Transparency = i --this makes it fade
                script.Parent.CanCollide = false --this makes it so you can go through it

                wait(0.1) -- how fast the fade is, you can change this.
            end 
            script.Parent.Destroy()
        end
            -- alternate method--   

        script.Parent:Destroy() -- simply destroys the brick
    end
end)
Ad

Answer this question