Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to remove equipped player tool?

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

✓ Accepted answer

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!")

2 comments

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?

0

Yes, it waits for the character to be loaded

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

This discussion is preserved as it was. New answers, comments, and votes are closed.