Cooldown on toggle script

i’d like to make something toggle-able, but with the script i have now the player can turn things on and off with no cooldown whatso ever

The idea of my script is:

if bool == false then
   bool = true
   print("on")
elseif bool = true then
   bool = false
   print("Off")
end

Is there a specific method to make a cooldown for this? if so id love to know. help is greatly appriciated :grinning:

1 Like
local bool = false
local cooldown = false
local cooldown_Number = 5 -- How many seconds to turn off cooldown.
if bool == false then
   if cooldown == false then
          bool = true
          print("on")
          cooldown = true
          task.wait(cooldown_Number)
          cooldown = false
    end
elseif bool == true then
    if cooldown = false then
          bool = false
          print("off")
          cooldown = true
          task.wait(cooldown_Number)
          cooldown = false
    end
end

I am not good answering to people but this might help you.

2 Likes

Yes, here

local cooldown = false
local function activate()
   if cooldown then return end
   cooldown = true
   if not bool then
      print("on")
   else
      print("Off")
   end
   bool = not bool
   task.wait(2)
   cooldown = false
end

activate() -- call this

NOTE: this only works if this is on the client, if it’s on the server you’ll need to create a cooldown for each player individually, let me know if you need that!

1 Like

Would i just run a for loop for every player in game? im not sure if ill need this on the server but i’d love to know how i can do it

Depends on what this cooldown is for. What is it for?

its just a toggle script, i plan on making an equiping/unequiping system and thats what it’ll be used for

Oh, seems like the script is only going to be used for one client, in this case this will work!

1 Like