Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cooldown on a pop-up GUI script doesn't work, why?

Reposted due to no answers being posted on the last question I asked. So I have a script that is supposed to make a GUI pop up if a player sits on a chair. It works fine. However, I only want the GUI to pop up every twenty seconds, so if a player jumps on the chair or sits multiple times during those twenty seconds it does not pop up. This is my code:

local debounce = true
local Part = game.Workspace.PC.Seat
Part.Touched:Connect(function(hit)
if hit.Parent == game.Players.LocalPlayer.Character then
game.Players.LocalPlayer.PlayerGui.VideoGui.Frame.Visible = true
debounce = false
wait(20)
debounce = true
end
end)


1 answer

✓ Accepted answer

You're not actually checking if the debounce is currently enabled.

local debounce = true
local Part = game.Workspace.PC.Seat
Part.Touched:Connect(function(hit)
if hit.Parent == game.Players.LocalPlayer.Character then
-- check if the debounce is active, and if so, end the function
if not debounce then return end
debounce = false
game.Players.LocalPlayer.PlayerGui.VideoGui.Frame.Visible = true
wait(20)
debounce = true
end
end)

1 comment

0

It works, thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.