Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a player Unequip a tool if they touch a certain part?

Asked by 3 years ago

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!

0
UnEquipTools is a typo. try replacing it with UnequipTools. NGC4637 602 — 3y
0
member can be a children (instance inside of it) or a property (e.g position, brickcolor etc.) or a function (in this case, UnequipTools) NGC4637 602 — 3y
0
Wow it was a typo all along! Thank you so much for pointing that out NGC4637 the script now works! businessman32246 2 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

Answer this question