How to make a "key press equip tool" with a incorperated "tool cooldown"

How to create script that on user input such as “q” equips a tool, and includes a cooldown to when you could re equip the tool?

Ive tried inserting a bool value named “can equip”,but that didnt work.

Any help or point in the right direction please?

1 Like

You’ll be using the api “UserInputService” – To get the key press for the letter “q”
https://developer.roblox.com/en-us/api-reference/class/UserInputService

Once you get the key press for q, there are a few ways of doing what you want
You can either
A. Parent the tool to StarterGear then bring it back to the backpack after the cooldown is done
B. Create a normal cooldown in the script by adding a true or false variable and checking if the cooldown is true or not
C. You can have a true or false variable in the tool and check when the tool is equipped to parent it to StarterGear and straight back to your backpack. This would make an affect of it unequipping itself.

If your just looking for a regular cooldown for a tool –

local Cooldown = false
if Cooldown == false then
Cooldown = true
coroutine.wrap(function()
wait(-- Whatever amount of time)
Cooldown = false
end)()
end
1 Like

It worked thanks for the help!!

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local backpack = player:WaitForChild("Backpack")
local tool = backpack:WaitForChild("Tool")

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(key, proc)
	if proc then
		return
	end
	
	if key.KeyCode == Enum.KeyCode.Q then
		humanoid:EquipTool(tool)
	elseif key.KeyCode == Enum.KeyCode.E then
		humanoid:UnequipTools()
	end
end)

Here’s a fairly simple example which will equip a tool given to the player from StarterPack when the “Q” key is pressed, it will also unequip any equipped tool when the “E” key is pressed. You can add support for cooldowns/multiple tools if necessary fairly easily.

1 Like
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local backpack = player:WaitForChild("Backpack")
local tool = backpack:WaitForChild("Tool")

local uis = game:GetService("UserInputService")

local debounce = false

uis.InputBegan:Connect(function(key, proc)
	if proc then
		return
	end

	if key.KeyCode == Enum.KeyCode.Q then
		if debounce then
			return
		end
		debounce = true
		humanoid:EquipTool(tool)
		task.wait(1)
		debounce = false
	elseif key.KeyCode == Enum.KeyCode.E then
		humanoid:UnequipTools()
	end
end)

I see you asked for a cooldown, so here’s the same script with a 1 second delay implemented between equips.

1 Like

Wow this is exactly what i was looking for ,thanks!

hello, i would like to know how i can add a tiny script inside this script. i just want a script when i press Q to spawn a tool in front of my Roblox character.