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

First Data saves and loads, but second wont. Any help?

Asked by
HaveASip 494 Moderation Voter
6 years ago

First data saves and loads, but second(which is backpack) wont load. I dont know why it wont, but I used same method in other games and them worked.

Thanks

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        wait()
        if not InStudio then
            local PlayerData

            PlayerData = DataStore:GetAsync(player.UserId)

            if PlayerData ~= nil then
                player.leaderstats.Points.Value = PlayerData[1]
                for index, tool in pairs(PlayerData[2]) do
                    local ToolSearch =  game:GetService("ServerStorage").ItemsShop:FindFirstChild(tool.Name)
                    if ToolSearch then
                        local Clone1 = ToolSearch:Clone()
                        local Clone2 = ToolSearch:Clone()

                        Clone1.Parent = player.StarterGear
                        Clone2.Parent = player.Backpack
                    end
                end
            else
                local ItemsTable = {}
                for index, tool in pairs(player.StarterGear:GetChildren()) do
                    if tool:IsA("Tool") then
                        if SS.ItemsShop:FindFirstChild(tool.Name) then
                            table.insert(ItemsTable, tool.Name)
                        end
                    end
                end
                local SaveTable  = {
                    player.leaderstats.Points.Value;
                    ItemsTable;
                    }
                DataStore:SetAsync(player.UserId, SaveTable)
            end
        end
    end)
end)
------
game.Players.PlayerRemoving:Connect(function(player)
    if not InStudio then
        local ItemsTable = {}
        for index, tool in pairs(player.StarterGear:GetChildren()) do
            if tool:IsA("Tool") then
                if SS.ItemsShop:FindFirstChild(tool.Name) then
                    table.insert(ItemsTable, tool.Name)
                end
            end
        end
        local SaveTable  = {
            player.leaderstats.Points.Value;
            ItemsTable;
            }
        DataStore:SetAsync(player.UserId, SaveTable)
    end
end)

Answer this question