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.
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