Hi Everyone! For some reason, Roblox is completely ignoring my for loop in my keep tools script shown below
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
print("Keep Tools Script: " .. player.Name .. " has died")
local listOfItems = player.Backpack:GetChildren()
print(listOfItems == nil) -- This is false according to the output
player.CharacterAdded:Connect(function(Char)
print(listOfItems == nil) -- also false in the output
for i = 1, #listOfItems do
print("B") -- does not print in the output
local item = listOfItems[i]
local itemClone = item:Clone()
local player = game.Players:GetPlayerFromCharacter(Char)
itemClone.Parent = player.Backpack
print("E") -- does not print in the output
end
print("Q")
end)
end)
end)
end)
listOfItems is not nil, it has the tools in it, but only the for loop in my code wont run. Any Ideas on how to fix this?
Any help is appreciated :)

7 comments
Maybe when the Player died, everything in the backpack will be delete. And you get the tool list from Backpack when the Player died, so it can be nil.
So you should save the Tools before the Player died and after the Tools added to the Backpack. And I suggest you to parent the Tools in ServerStorage.
but the thing is that the prints saying print(listOfItems == nil) return false, so if the backpack is truly nil, what could the prints be saying? (Also, ServerStorage deletes everything in it, so i dont have access to it i think).
:GetChildren() will return a table even there is no children. Mean when you do print(listOfItems == nil) it will false, because the table is exist even there is no Tools in it. Try print(listOfItems[1] == nil) to check is there any Tools in the table.
And if your script is LocalScript then you can't access ServerStorage, try ReplicatedStorage instead.
The objects in ServerStorage still exists, but not for the client. It can only be accesable for the Server in a Server or Module script
for i = 1, #listOfItems,1 do (try this, maybe it is because of the missing increase integer)