Hi, I have a script in a brick that's supposed to make a sound play when the brick is touched by the player. It looks like this:
local SP = script.Parent
function onTouch(hit)
local H = hit.Parent:FindFirstChild("Humanoid")
if H ~= nil then
SP.S:Play()
end
end
script.Parent.Touched:connect(onTouch)
The problem is, I can't find a way to make it wait a little while after touched to perform the action again. The sound plays repeatedly so long as the player is touching the brick. I thought the obvious solution was to add a wait() after when the sound plays, but that didn't work, nor did making it wait until the player is finished touching it to execute again. It may be a simple answer, but how can I fix this?

2 comments
Thank you to everyone who answered! I had no idea about the debounce function.
No problem.