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 3 years ago

I tried this code but didn't work:

function deletePlayersItens()
    local player = game.Players:GetPlayers()
    for _, tool in ipairs(player.Backpack:GetChildren()) do
        if tool:IsA("Tool") then
            tool:Destroy()
        end
    end --Deletes all tools from Backpack
    if player.Character:FindFirstChildOfClass("Tool") then
        player.Character:FindFirstChildOfClass("Tool"):Destroy()
    end --Deletes Equipped Tool
end

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 3 years ago

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


function deletePlayersItens() local players = game.Players:GetPlayers() for I, player in pairs(players) do for _, tool in ipairs(player.Backpack:GetChildren()) do if tool:IsA("Tool") then tool:Destroy() end end --Deletes all tools from Backpack if player.Character:FindFirstChildOfClass("Tool") then player.Character:FindFirstChildOfClass("Tool"):Destroy() end --Deletes Equipped Tool end end
0
worked thx a lot LyricalFrog3 45 — 3y
Ad

Answer this question