How to make a cooldown for a GUI button

Greetings,

I need to know how can I make my GUI button have a cooldown so that the auto clicker won’t have such a big use.

button.MouseButton1Click:Connect(function()

end)

Thanks!

1 Like

You could use the concept of debounces.

local debounce = false


script.Parent.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true 
      -- code goes here. because debounce is now true, nothing else below here will run.
		task.wait(5) -- wait 5 seconds, then reenable the button to be clicked again.
		debounce = false
	end
end)
5 Likes

Works well, thank you a lot! char limit

just a tip do cooldowns from the server side too since players can disable anything in their client

As long as it isn’t really important, you don’t need to do that. But, if it were something like “click to gain cash” then yes, you would have to implement the same cooldown on the server, but I would do task.delay on the server so it doesn’t yield the script.