Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)

0
when you say get children, it returns a table. You cannot destroy a table tonyv537 95 — 5y
0
Thanks for telling! StrategicPlayZ 58 — 5y

1 answer

Log in to vote
1
Answered by
HaveASip 494 Moderation Voter
5 years ago
Edited 5 years ago

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
0
Thanks! You solved my problem. StrategicPlayZ 58 — 5y
Ad

Answer this question