Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Cooldown for part.Touched:connect()?

Asked by 7 years ago
Edited 7 years ago

Hello y'all,

I'll start off by showing what my code is at the moment:

Shrek = game.Workspace.Shrek.Head
Allstarsound = game.Workspace.Allstar
ShrekTouched = Shrek.Touched
function Allstar()
    Allstarsound:Play()
    wait (59)
    Allstarsound:Stop()
end

Shrek.Touched:connect(Allstar)

I want the "Shrek.Touched:connect(Allstar)" part to have a cooldown, so the sound wont start again when you start it. I tried the following code:

if Shrek.Touched then
    Allstar()
    wait (75)
end

Which ended me up with the sound to be played when joined.

If you have any questions, feel free to ask me.

1 answer

Log in to vote
0
Answered by 7 years ago

You can use a cooldown debounce.

Shrek = game.Workspace.Shrek.Head
Allstarsound = game.Workspace.Allstar

local isInCooldown = false
local cooldownTime = 75

function Allstar()
    if isInCooldown then return end
    Allstarsound:Play()
    wait (59)
    Allstarsound:Stop()
    isInCooldown = true
    wait(cooldownTime)
    isInCooldown = false
end

Shrek.Touched:connect(Allstar)

0
Worked after I did some adjustments, because it would play the song, wait 59 seconds and THEN do the cooldown which ended up to not work correctly. Got it now, thanks anyways! Abnormaalz 0 — 7y
0
Ohh. lol. I didn't even see you had the wait(50) TestingPlace1337 51 — 7y
Ad

Answer this question