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:
1 | local scream = "rbxassetid://292124372" |
2 | local works = game:GetService( "Workspace" ) |
3 | local hitboxx = works.scream.hitbox |
4 | hitboxx.Touched:connect( function (h) |
5 | local sound = Instance.new( "Sound" , hitboxx.Parent.Head) |
6 | sound.SoundId = scream |
7 | sound:Play() |
8 |
9 | end ) |
something wrong?
You need to make a debounce.
01 | local scream = "rbxassetid://292124372" |
02 | local works = game:GetService( "Workspace" ) |
03 | local hitboxx = works.scream.hitbox |
04 | local cooldown = 5 --how many seconds to wait before doing it again |
05 | local debounce = false |
06 | hitboxx.Touched:connect( function (h) |
07 | if debounce = = false then --checking if debounce is false |
08 | debounce = true --making debounce true |
09 | local sound = Instance.new( "Sound" , hitboxx.Parent.Head) |
10 | sound.SoundId = scream |
11 | sound:Play() |
12 | wait(cooldown) --waiting the cooldown |
13 | debounce = false --making the debounce false again |
14 | end |
15 | end ) |
The script should work, if you got any questions ask me.