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

I want to remove all the tools in a player's backpack but it doesn't work. What is the problem here?

I need to make a script that destroys all the gears in the player's backpack when executed. The script I have made up till now is:

local children = player.Backpack:GetChildren()
if (children) then
	children:Destroy()
end

I get this error:

ServerScriptService.RemoteEventsScripts.Client To Server.RelatedToTeams.NeutralTeam:11: attempt to call method 'Destroy' (a nil value)

2 comments

0

when you say get children, it returns a table. You cannot destroy a table

0

Thanks for telling!

1 answer

✓ Accepted answer

For problems like that you need to use for loop.

Here is your script:

local Tools = player.Backpack:GetChildren() -- gets the children of the backpack

for index, object in pairs(Tools) do
	if object:IsA("Tool") then -- checks if current child is a tool
		object:Destroy() -- destroy
	end
end

1 comment

0

Thanks! You solved my problem.

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