Currently working on a round based fighting game. I already have a round system set in place, as well as a script that gives all players a knife at the start of the round. However, I do not know how to remove it from all player's backpacks at the end of the round. What is the correct scripting for this? Thanks.
Iterate through all the Players' backpacks and Remove their tools.
local function removeTools() local players = game.Players:GetPlayers() -- Table of all players in the game for _, player in pairs(players) do -- Use a for loop to iterate through the players table local backpack = player:FindFirstChild("Backpack") -- Locate the backpack if backpack then -- If the backpack was succesfully found... backpack:ClearAllChildren() -- Remove everything from their Backpack end end end removeTools()
This code should work...
local player = game.Players:GetPlayers() local backpack = player:WaitForChild("Backpack") local character = player.Character or player.CharacterAdded:Wait() local Itemstodestory = {"TOOL1", "TOOL2", "TOOL3", "TOOL4", "TOOL5"} local function Desteoyfunction(tools) for _, launcher in pairs(Itemstodestory) do local tool = tools:FindFirstChild(Desteoyfunction) if tool and tool:IsA("Tool") then tool:Destroy() end end end Desteoyfunction (backpack) Desteoyfunction (character)
if you want to clear the children of the tools then do this
for _,v in pairs(game.Players:GetPlayers()) do v.Backpack:ClearAllChildren() end
This should work:
for _,v in pairs(game.Players:GetPlayers()) do local bp = v:FindFirstChild("Backpack") if bp then bp:ClearAllChildren() end end
If the Item is equiped:
for _,w in pairs(game.workspace:GetDescendants()) do if w:IsA("Tool") and game.Players:FindFirstChild(w.Parent.Name) then w:Destroy() end