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);
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)