GUI cool down script

Hey everyone! Ok so I was wondering if anyone had a GUI cool down script so the player cannot click the gui and have it run the script too many times that it crashes. Also if you have one where it gives like a message like when player points were a thing.

1 Like

You can make a debounce. It makes your script wait a bit when button is clicked.
More about the debounce system here: Debounce Patterns | Documentation - Roblox Creator Hub

1 Like

Yeah but kinda want a cool down script trying to avoid the issue not delay it. I know case clicker had or has one when it stops you for a while so you don’t get allot of case bux.

Simple!

Example:

local Player = game.Players.LocalPlayer 
local Mouse = script.Parent
local timez = 10 -- your time
 
Mouse.MouseButton1Click:Connect(function()
   print("hey") --your code example
wait(.1)
script.Disabled = true
wait(timez)
script.Disabled = false
--player can't click more than once

end)

Hope this works for you!

4 Likes

If you disable the script, won’t the code be stopped?

By the player points message, do you mean the ones in the bottom right of the screen? If so your looking for “SendNotification” and it can be found here: StarterGui | Documentation - Roblox Creator Hub

1 Like

No, we added a wait 10 statement and the script reactivates. I tested this before I posted, the scripts functionalities are ended, and the first request made by the click finishes by reactivating the script after the specified time.

4 Likes

Ok thanks everyone for your help! Kensizo’s script worked for me.

No problem, good luck on your game, hope it all goes well.

2 Likes

The recommended method should be debounce, a boolean value that is checked with an if statement. The code @Kensizo provided is an uncertain case; it can stop other inputs in other functions in the same script.

local Player = game:GetService("Players").LocalPlayer -- Safe to use GetService()
local Button = script.Parent -- This is the button AKA the input object.
local Cooldown = 10 -- seconds
local Debounce = false -- Set this boolean

Mouse.MouseButton1Click:Connect(function()
   if Debounce then
      return
   end
   Debounce = true

   print("Hello")

   wait(Cooldown)
   Debounce = false
end)
8 Likes