Today I found out, when a player equips a tool, it leaves the backpack and goes to the player’s character, so I realized this line of code won’t work anymore:
local tool = game.Players.LocalPlayer:WaitForChild("Backpack"):GetChildren()
Is there another way to get a tool in the player’s character that can have any name?
Well I would not use “or“. Incase the player has more then 1 tool the Character would not be searched.
Also, this is how you can do it locally for the character, you had it slightly wrong.
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local tool = char:FindFirstChildWhichIsA(“Tool“)
I’m actually using a loop in the process, it won’t work.
local tool = game.Players.LocalPlayer.Backpack:GetChildren() -- we will take the tool away from the player
local plrtool = game.Players.LocalPlayer:WaitForChild("Character"):FindFirstChildWhichIsA("Tool")
plrtool:Destroy()
for _, tools in tool do
tools:Destroy()
for _, v in pairs(game.Players.LocalPlayer.Backpack:GetChildren()) do
v:Destroy()
end
for _,v in pairs(game.Players.LocalPlayer:WaitForChild(“Character“):GetChildren()) do
if v:IsA(“Tool“) then
v:Destroy()
end
end
This could also work (It is still running locally):
local player = game.Players.LocalPlayer
local character = player.Character
local function RemoveTools()
player.Backpack:ClearAllChildren()
local tool = character:FindFirstChildOfClass("Tool")
if tool then tool:Destroy() end
end
RemoveTools()