I am trying to make it so when a player touches a part, it will make a sound. But when touched again, the sound doesn't play. How do I fix this?
Here's the Script I used:
local debounce = false function onTouched(hit) if debounce == true then return end debounce = true script.Parent.Music:play() end debounce = false wait (2) script.Parent.Touched:connect(onTouched)
i was a bit confused by your script, so i changed some values to make it more understandable
local playable = true function onTouched(hit) if hit.Parent:FindFirstChild("Humanoid") then ---checks to see if a player touched the brick if playable == true then --- checks if it is able to play --- if its able to playe then run this code playable = false script.Parent.Music:play() wait(2) ---waits for 2 seconds before being able to play again playable = true end end end script.Parent.Touched:connect(onTouched)
see, when something touches the brick it runs the function "onTouched", so everything inside that function will run, so thats why your debounce didnt reset .