I made a script that makes it so that when a player clicks on my selected model, it plays a sound How can i make it so that after a player clicks on the part once it does not play again when clicking on it a second time?
This is the script I'm currently using:
Brick = script.Parent Sound = Brick.Sound2 function onClicked() Sound:Play() end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Change :connect to :Connect in your last line.
local brick = script.Parent local sound = brick.Sound2 local clicks = 0 function onClick(plr) clicks = clicks + 1 sound:Play() if clicks == 1 then sound.Parent = nil -- didn’t use :Destroy() just in case you wanted it to be re-parented end end
Make a debounce
variable, and also no need to check the counter, as that might be slightly more complicated:
local brick = script.Parent local sound = brick.Sound2 local debounce = false function onClick(plr) if debounce then return end debounce = true -- This will make it not run again. clicks = clicks + 1 sound:Play() sound.Parent = nil end