Hello! I'm having trouble scripting a Part that when touched forces a player to Unequip any tool they have Equipped. I've just started to learn how to script and I really don't have enough experience in scripting to find a solution to this, so help is appreciated!
So far this is what I've come up with:
local door = script.Parent local function remove(otherPart) local humanoid = otherPart.Parent:FindFirstChild('Humanoid') local player = game.Players:FindFirstChild(otherPart.Parent.Name) if humanoid and player then local inHand = otherPart.Parent:FindFirstChildWhichIsA('Tool') local inBackpack = player.Backpack:FindFirstChildWhichIsA('Tool') if inHand then humanoid:UnEquipTools() --attempts to unequip the player's tool but it gives me an error. end if inBackpack then inBackpack:Destroy() -- destroys all tools in the player's backpack. end end end door.Touched:Connect(remove)
The goal of the script is to Unequip any tool that the player is holding and to destroy all tools in the player's Backpack when the player touches a certain Part. The line that I'm receiving an error from is the one that says (humanoid:UnEquipTools()).
After touching the Part that is supposed to unequip and remove all tools from the player, the script outputs this error:
"UnEquipTools is not a valid member of Humanoid "Workspace.businessman32246(player name).Humanoid"
I'm not really sure what this means and can't find a solution to this error.
I hope this question makes sense because it was pretty hard to explain in writing lol. Thanks!
The problem is very simple. In line 17 you wrote UnEquipTools()
instead of UnequipTools()
[The "E" should be a lower case later: "e"]
Here is the fixed script:
local door = script.Parent local function remove(otherPart) local humanoid = otherPart.Parent:FindFirstChild('Humanoid') local player = game.Players:FindFirstChild(otherPart.Parent.Name) if humanoid and player then local inHand = otherPart.Parent:FindFirstChildWhichIsA('Tool') local inBackpack = player.Backpack:FindFirstChildWhichIsA('Tool') if inHand then humanoid:UnequipTools() -- It will work now end if inBackpack then inBackpack:Destroy() end end end door.Touched:Connect(remove)