Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.