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 a tool from all players' backpack??

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.

3 answers

✓ Accepted answer

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

2 comments

0

Thanks!

0

c :

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