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

How do i check and unequip a tool in a local script?

Asked by
7Woofy 0
2 years ago
Edited 2 years ago

so this is inside a button that clears your inventory.

script.Parent.Visible = false
local p = game.Players.LocalPlayer
local items = p.Backpack:FindFirstChildOfClass("Tool")
local activated = false

script.Parent.MouseButton1Click:connect(function()
    local tool = game.Players.LocalPlayer.Backpack:GetChildren()

    script.Parent.Parent.Popcatsword.Visible = true
    script.Parent.Parent.TextButton.Visible = true
    script.Parent.Parent.shrek.Visible = true
    script.Parent.Parent.bow.Visible = true 
    for i, child in ipairs(tool) do
        child:Activate()
        child:Deactivate()
        child:Destroy()
    end
    script.Parent.Visible = false
end)

1 answer

Log in to vote
1
Answered by
bbissell 346 Moderation Voter
2 years ago
Edited 2 years ago

I was a little confused by your post title, but if you're looking for a button that clears your inventory then this would do it:

script.Parent.MouseButton1Click:connect(function()
    for _, tool in ipairs(game.Players.LocalPlayer.Backpack) do
        if Tool:IsA("Tool") then
            Tool:Destroy()
        end
    end
end)

You can add any of the visibility settings you had as needed.

I'm not entirely sure what you were trying to accomplish with activating and deactivating the tool. If that was your intent, let me know and I can try to help.

0
Ok, so sorry about that, basically this is a local script in a button that is supposed to remove all items in your inventory. I wanted to have one that gives you weapons and then when you want to switch a weapon it deletes it from your inventory. It worked fine when a tool wasn't equipped, but when it was it didn't delete the tool. I want to check if it is equipped then unequip it so it can delete 7Woofy 0 — 2y
Ad

Answer this question