Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does roblox only ignore my for loop when I try to give them their tools back?

Asked by 4 years ago

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 :)

0
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. Block_manvn 395 — 4y
0
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. Block_manvn 395 — 4y
0
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). JustAnotherGaming 48 — 4y
0
: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. Block_manvn 395 — 4y
View all comments (3 more)
0
And if your script is LocalScript then you can't access ServerStorage, try ReplicatedStorage instead. Block_manvn 395 — 4y
0
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 Spjureeedd 385 — 4y
0
for i = 1, #listOfItems,1 do (try this, maybe it is because of the missing increase integer) Void_Frost 571 — 4y

Answer this question