So I'm trying to make it so when you click on a textbutton it adds 1. I made that here:
block = 1 game.ReplicatedStorage.anything.OnServerEvent:Connect(function(player) player.leaderstats.Blocks.Value = player.leaderstats.Blocks.Value + block wait(1) end)
But, if you use an autoclicker, you can get hundreds of points in seconds. I was wondering how you could add a cooldown so you only get a point every 0.5 seconds? Thanks.
Use a debounce.
-- LocalScript inside the button local ReplicatedStorage = game:GetService("ReplicatedStorage") local remote = ReplicatedStorage:WaitForChild("anything") local button = script.Parent local clickable = true -- this will be our debounce button.MouseButton1Down:Connect(function() if clickable then -- if clickable is set to true clickable = false remote:FireServer() task.delay(0.5, function() -- this will turn clickable to true again after 0.5 seconds clickable = true end) end end)
An alternative is the Active
property.
-- LocalScript inside the button local ReplicatedStorage = game:GetService("ReplicatedStorage") local remote = ReplicatedStorage:WaitForChild("anything") local button = script.Parent button.MouseButton1Down:Connect(function() button.Active = false -- deactivates the button, making the button not clickable remote:FireServer() task.delay(0.5, function() -- this will make the button clickable again after 0.5 seconds button.Active = true end) end)