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

Delete ALL players itens from backpack and equipped (character) ????

Asked by 4 years ago

I tried this code but didn't work:

01function deletePlayersItens()
02    local player = game.Players:GetPlayers()
03    for _, tool in ipairs(player.Backpack:GetChildren()) do
04        if tool:IsA("Tool") then
05            tool:Destroy()
06        end
07    end --Deletes all tools from Backpack
08    if player.Character:FindFirstChildOfClass("Tool") then
09        player.Character:FindFirstChildOfClass("Tool"):Destroy()
10    end --Deletes Equipped Tool
11end

Error: ServerScriptService.MainScript:14: attempt to index nil with 'GetChildren' - Server - MainScript:14

Please someone help me, also I need it to delete equipped itens as it needs to reset to get back to the lobby.

1 answer

Log in to vote
0
Answered by 4 years ago

The player variable seems to be a table you can resolve this by making a for loop as such:

01function deletePlayersItens()
02    local players = game.Players:GetPlayers()
03    for I, player in pairs(players) do
04         for _, tool in ipairs(player.Backpack:GetChildren()) do
05            if tool:IsA("Tool") then
06                tool:Destroy()
07                end
08      end --Deletes all tools from Backpack
09        if player.Character:FindFirstChildOfClass("Tool") then
10            player.Character:FindFirstChildOfClass("Tool"):Destroy()
11        end --Deletes Equipped Tool
12    end
13end
0
worked thx a lot LyricalFrog3 45 — 4y
Ad

Answer this question