Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

worked thx a lot

This discussion is preserved as it was. New answers, comments, and votes are closed.