I created a script that makes a humanoid say something when someone comes close, everything works fine, but the problem is that the humanoid is repeated the sound infinite times when a player gets close. I would like him to speak only once and then keep repeating after 5 seconds he finished speaking, can anyone help? another problem is that the sound is played before the event happens, watch the script: script:
local scream = "rbxassetid://292124372" local works = game:GetService("Workspace") local hitboxx = works.scream.hitbox hitboxx.Touched:connect(function(h) local sound = Instance.new("Sound", hitboxx.Parent.Head) sound.SoundId = scream sound:Play() end)
something wrong?
You need to make a debounce.
local scream = "rbxassetid://292124372" local works = game:GetService("Workspace") local hitboxx = works.scream.hitbox local cooldown = 5 --how many seconds to wait before doing it again local debounce = false hitboxx.Touched:connect(function(h) if debounce == false then --checking if debounce is false debounce = true --making debounce true local sound = Instance.new("Sound", hitboxx.Parent.Head) sound.SoundId = scream sound:Play() wait(cooldown) --waiting the cooldown debounce = false --making the debounce false again end end)
The script should work, if you got any questions ask me.