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?

1local pack = player.Backpack
2            local findSword = pack:FindFirstChild("ClassicSword")
3            local Char = workspace:FindFirstChild("Player")
4            local equippedSword = Char:FindFirstChild("ClassicSword")
5            if findSword then                           
6                findSword:Destroy()
7            elseif equippedSword then
8                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.

1local pack = player.Backpack
2            local findSword = pack:FindFirstChild("ClassicSword")
3            local Char = player.Character or player.CharacterAdded:Wait()
4            local equippedSword = Char:FindFirstChild("ClassicSword")
5            if findSword then                           
6                findSword:Destroy()
7            elseif equippedSword then
8                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