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

How would I add a cooldown to this textbutton script?

How would I add a cooldown to this textbutton script, so that people won't be able to spam it and glitch the button?

local b = script.Parent
local f = script.Parent.Parent.Frame

b.MouseButton1Click:Connect(function()
	f.Visible = true
end)

1 answer

✓ Accepted answer

Simple! All you need to do is to add a debounce also known as a cooldown.

local b = script.Parent
local f = script.Parent.Parent.Frame
local canClick = true

b.MouseButton1Click:Connect(function()
	if canClick then -- check if value is true
		canClick = false -- set this variable to false so that previous statement cant run until value is true
		f.Visible = true
		
		wait(1) -- cooldown time
		canClick = true -- set value back to true
	end
end)

Hope this helps. If there's anything wrong, do let me know. Remember to accept if it helps. :D

1 comment

0

Thank you :)

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