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)
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)
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
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Thank you :)