I'm having trouble with a certain script. I don't know how to stop a sound from playing multiple times when you touch a brick. It keeps repeating and I have no answer for this.
This is the whole script v
local Part = script.Parent local Sound1 = script.Parent.Sound1 Part.Touched:connect(function(hit) local hum = hit.Parent:WaitForChild('Humanoid') if hum then while true do Sound1:Play() wait(1) --wait(0.82800000000000007) break end end end)
p.s I'm new to scripting, so go easy on me.
Once upon a time, there was debounce. Debounce is used to help in these types of situations, by stopping an event from firing multiple times.
local Part = script.Parent local Sound1 = script.Parent.Sound1 local deb = false Part.Touched:connect(function(hit) local hum = hit.Parent:WaitForChild('Humanoid') if hum and deb == false then deb = true Sound1:Play() wait(1) deb = false Sound1:Stop() end end)
You also had an unnecessary while loop.