Force unequip tool when press Q

Ive been trying to make it when u press Q the tool unequips. But it doesnt seem to work and i dont know why, heres the script its placed in my tool

local UIS = game:GetService(“UserInputService”)
local plr = game:GetService(“Players”):WaitForChild(“LocalPlayer”)
local key = Enum.KeyCode.Q
local tool = script.Parent
local humanoid = plr.Character:WaitForChild(“Humanoid”)

UIS.InputBegan:Connect(function(key, gp)
if key.KeyCode == key then
if UIS:GetFocusedTextBox() == nil then
humanoid:UnequipTool(tool)
end
end
end)

You have two variables named key

because, Humanoid:UnequipTool doesn’t exist. use: Humanoid:UnequipTools()

ALSO, LocalPlayer is a property of Players meaning you cannot use :WaitForChild() on it.

MAKE SURE TO ENABLE ‘REJECTCHARACTERDELETIONS’ IN WORKSPACE (PROPERTY)

Fixed Script:

script.RunContext = Enum.RunContext.Server --making sure it's server-sided
local CAS = game:GetService("ContextActionService")
local key = Enum.KeyCode.Q
local tool = script.Parent
local plr
if tool.Parent:IsA("Model" then
game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
else
plr = tool.Parent.Parent
end

CAS:BindAction("Unequip", function() plr.Character.Humanoid:UnequipTools() end, false, key)
1 Like