local player = game:GetService("Players").LocalPlayer;
local mouse = player:GetMouse();
local tool = player.Backpack.StoneSword;
mouse.KeyDown:connect(function(key)
if key == "q" then
player.Character.Humanoid:EquipTool(tool);
end
if key == "e" then
player.Character.Humanoid:UnequipTool(tool); -- I have a problem with this part
end
end);
✓ ANSWER ACCEPTED
Press E to equip a tool And again for Unequip tool?
1 answer
✓ Accepted answer
UnequipTool is not a function of the Humanoid object. Parent the tool to their Backpack.
Also, the KeyDown event is deprecated. Use InputBegan.
local player = game.Players.LocalPlayer;
local backpack = player:WaitForChild("Backpack");
local tool = backpack:WaitForChild("StoneSword");
local char = player.Character or player.CharacterAdded:Wait(); --Character
local hum = char:WaitForChild("Humanoid") --Humanoid
local uis = game:GetService("UserInputService") --service for InputBegan
local key = Enum.KeyCode.E --key to tap
uis.InputBegan:Connect(function(i,p) --'connect' is deprecated
if p then return end --if they're typing do nothing
if i.KeyCode == key then --If they've hit the correct key
if not char:FindFirstChild(tool.Name) then --and tool is not equipped
hum:EquipTool(tool); --equip it
else --if tool is equipped
tool.Parent = backpack; --unequip it.
end
end
end)
3 comments
0
When i use it and then UnEquip it dont wil Eqip againe please help
0
Are you pressing the same key? I noticed your title stated "E" for equipping AND unequipping yet your code tried to use "Q" for equipping and "E" for unequipping
0
No would like that if you press E that you have your weapon and if you press 1x E that it goes away but you can use your weapon
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I'm pretty sure that in the output there is an error stating that UnequipTool is not a valid member of Humanoid. You should state errors next time.