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

How would I add a cooldown to this textbutton script?

Asked by
2jxi 4
3 years ago

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

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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

0
Thank you :) 2jxi 4 — 3y
Ad

Answer this question