I was trying to remove a sword even when the player equipped it. Here is the code I typed in:
for _,Player in pairs(game.Players:GetPlayers()) do local sword = Player.Backpack:FindFirstChild('ClassicSword') if sword then sword:Destroy() end end
I tested it but didn't work. In Explorer, there was nothing in BackPack (which could be found in Player). But the sword was still in the player's hand. What should I do? (If this question was answered, pls send me a link to it)
When they player equips a tool, it moves from their backpack into their character. This is actually quite a simply fix, all you have to do is check whether or not the tool is in the players backpack OR the players character.
Here's what that might look like:
for _,Player in pairs(game.Players:GetPlayers()) do if Player.Backpack:FindFirstChild('ClassicSword') then Player.Backpack:FindFirstChild('ClassicSword'):Destroy() elseif Player.Character:FindFirstChild('ClassicSword') then Player.Character:FindFirstChild('ClassicSword'):Destroy() end end
Anyways, I hope this helped. If not, or if you have any further problems/questions, please leave a comment below, and I'll see what I can do.
Well, if it's in their hand, that means it's within their Character! You'll need to go through the Character, see what is a tool, and remove it!
for i,v in pairs(game.Players:GetPlayers()) do local sword = Player.Backpack:FindFirstChild('ClassicSword') if sword then sword:Destroy() else for _,b in pairs(v.Character:GetChildren()) do -- Go through the character if b.Name == "ClassicSword" then -- or if b:IsA("Tool") b:Destroy() end end end end