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

How to make a function wait until touched event is done before firing again?

Asked by 2 years ago

So im trying to make a part that makes it transparency 1 when touched and then the transparency will go back to 0 after 3 seconds but if i touch it again then the function will fire again and here is my script:

local TransparencyPart = script.Parent

TransparencyPart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then TransparencyPart.Transparency = 1 wait(3) TransparencyPart.Transparency = 0 end end)

1 answer

Log in to vote
0
Answered by 2 years ago

I have no clue what you did wrong this code works for me:

local TransparencyPart = script.Parent

TransparencyPart.Touched:Connect(function(hit)

    if hit.Parent:FindFirstChild("Humanoid") then TransparencyPart.Transparency = 1 

    wait(3) 

    TransparencyPart.Transparency = 0 
    end
end)

Good luck!

Ad

Answer this question