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

I need to remove tools from a players backpack using a script, Any help?

I have been trying to remove tools using scripts for ages, Please may you help, These are all the codes I have tried.

In a local script, I did

game.Players.LocalPlayer.Backpack:Destroy()

Any other help?

I also tried

 for i,v in pairs(game.Players:GetChildren()) do --Get all children of players
    Backpack = v:FindFirstChild("Backpack",true)
    if Backpack ~= nil then  --Check if the child has a backpack
        c = Backpack:GetChildren() --Get the children of the backpack
        for i = 1,#c do
            c[i]:Destroy() --Use Destroy method instead
        end
    end
end)

But still didn't work

2 comments

2

Backpack:ClearAllChildren()

0

Try Print Debugging and :ClearAllChildren()

2 answers

on join

local f = game.Players.LocalPlayer.BackPack:GetChildren()
for i = 1, #f do
if f[i].className == "Tool" then
f[i]:Remove()
end
end

or ontouch

function c(hit)
	hit.Parent:WaitForChild("Humanoid") --check if hit is a player
	local user = hit.Parent.Name
	local f = game.Players[user].Backpack:GetChildren()
	for i = 1, #f do
		if f[i].className=="Tool" then -- checks if its a tool
			f[i]:Remove()
		else
			print("item in backpack isnt a tool")
		end
	end
end
-- Assuming local script
for i,v in pairs(game.Players.LocalPlayer.BackPack:GetChildren()) do
	if v:IsA("Tool") then
		v:Destroy()
	end
end)

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