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

How to remove equipped player tool?

Asked by
pie9909 18
4 years ago

Hello, so I've figured out how to remove tools in backpack, but when you equip a tool it wont get deleted since it's no longer in the backpack, could somebody tell me what I'm missing?

        local pack = player.Backpack
                    local findSword = pack:FindFirstChild("ClassicSword")
                    local Char = workspace:FindFirstChild("Player")
                    local equippedSword = Char:FindFirstChild("ClassicSword")
                    if findSword then                            
                        findSword:Destroy()
                    elseif equippedSword then
                        print("sword is equipped!")

2 answers

Log in to vote
0
Answered by
OhManXDXD 445 Moderation Voter
4 years ago

Instead of using Workspace:FindFirstChild(“Player) (which wouldn’t work anyway because it would be looking for a child of workspace named “Player”)

Use player.Character or player.CharacterAdded:Wait() to look for the character.


local pack = player.Backpack local findSword = pack:FindFirstChild("ClassicSword") local Char = player.Character or player.CharacterAdded:Wait() local equippedSword = Char:FindFirstChild("ClassicSword") if findSword then findSword:Destroy() elseif equippedSword then print("sword is equipped!")
0
OH thanks! so player.Character define's the player's character already, what does the wait function do? wait for character to be added? pie9909 18 — 4y
0
Yes, it waits for the character to be loaded OhManXDXD 445 — 4y
Ad
Log in to vote
0
Answered by
MpAlex 16
4 years ago

try with function, then add script.Parent.Equipped:Connect(YourFunctionName)

Answer this question