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
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.
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.
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.