How to add a equip cooldown for a tool?

Hey.
Pretty simple, just looking on if it’s possible to add a cooldown for how quick you can equip a tool.

e.g. I have a tool in my backpack and take it out, If I put it away 2 seconds must elapse before I can re-take it out.

3 Likes

I think you could use RunService.Stepped to check when the last equipped time was, not entirely certain though

1 Like

Oh gotchu. Do ya know how I’d figure out if the tool has been equip?
My thought currently would be checking if it’s in the Backpack / Workspace model.

There’s actually a specific Event on the Tool called Equipped (WOW GENIUS IDEA)

It pretty much is what it says aha, the Equipped Event fires whenever the Tool gets equipped so say I have this:

local Tool = script.Parent --This Tool variable is referring to the script.Parent (Or the Tool's Instance) Aka, script > Tool

Tool.Equipped:Connect(function()
    print("The tool has been equipped!")
end)

Some Events are pretty straightforward I think

Ohhh completely forgot about that event lol.

But, with that event, is there a way to prevent the tool from being re-equipped until the certain cooldown time has elapsed?

What you can do is use debounce.

local equipped = false

local cooldown = amount

local tool = -- your tool

tool.Equipped:Connect(function()
      if not equipped then
         -- your function
      else
          player.Character.Humanoid:UnequipTools()
      end
end)

tool.Unequipped:Connect(function()
    equipped = true

    wait(cooldown)

    equipped = false
end)

EDIT: Polished the code a bit so it is simpler

2 Likes

Ohh, never knew about the Humanoid UnequipTools. So this makes it much better, thank you!

1 Like

Hey, so I just tried the method and I kept getting this warning:
image

Unfortunately, you cant disable the standard equip/unequip keys since the code used for it uses UserInputService if I recall.

What you can do is add a small wait(), or better yet, game:GetService("RunService").RenderStepped:Wait() before unequipping the tool again.

That sadly doesn’t work either, there’s a glitch (on roblox’s side) which completely destory’s my game due to it, unfortunately the unequip needss to be near instant else it doesn’t patch : (

This error is kind of confusing me because it says you are trying to parent the sword to something but in my code I don’t do anything like that.

Equipping tools moves that tool to the Player’s Character.
Unequipping them moves it to the Player’s Backpack.

Edit: reversed

I’ve also run into this dilemma. I have been unable to find a way to properly debounce the equip/unequip events. Sure I can debounce the code that runs during those events, but that unfortunately doesn’t stop the tool from switching states as equipped/unequipped. It would be nice if there was an enable/disable toggle for the tool that would turn on/off the ability for the player to fire the equip/unequip events. There is such an option for the Activate/Deactivate events but that is useless if your tool is programmed to react to the actual equip/dequip of the tool. Even just the ability to force the tool back into a state would be helpful. Like oh you fired the dequip event, but the code rejects that and keeps the tool in equipped state or vice-versa.

I know this post is pretty old, but for anyone in the future running into this problem, I got around it by just disabling the coregui for the backpack and reenabling it after the cooldown ends

local StarterGui = game:GetService("StarterGui")
local Tool = script.Parent
local Cooldown = 1 -- in seconds

Tool.Equipped:Connect(function()
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) -- disable backpack gui
	delay(Cooldown,function()
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true) -- enable backpack gui
	end)
end)

Tool.Unequipped:Connect(function() -- do above again but for unequpping
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	delay(Cooldown,function()
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	end)
end)
11 Likes

Or just do this i think?

local tool = --your tool path
local equipped = false

tool.Equipped:Connect(function()
     equipped = false
     task.delay(yourcooldownnumber,function()
        equipped = true
end)

tool.Unequipped:Connect(function()
equipped = false
end)