I tried this code but didn't work:
01 | function 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 |
11 | 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:
01 | function 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 |
13 | end |