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

Why wont this save/load multiple values?

Asked by 7 years ago
local Storage = game:GetService('DataStoreService'):GetDataStore('SkinsHolder')

game.Players.PlayerAdded:Connect(function(player)
    local skins = game.ServerStorage.Lazors:Clone()
    skins.Parent = player
    local savedskins = Storage:GetAsync(player.userId .. "-Skins")
    if savedskins ~= nil then 
        for i,v in pairs(skins:GetChildren()) do
            v.Value = savedskins 
        end
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    local id = player.userId
    for i,v in pairs(player.Lazors:GetChildren()) do
        local skinsvalue = v.Value
        for i,v in pairs(player.Lazors:GetChildren()) do
            Storage:SetAsync(id.. "-Skins",skinsvalue)
        end
    end
end)

Its supposed to save the values(which are bool values) and load them if they are true or false. Why will this not work?

0
Are there any errors printed? MrLonely1221 701 — 7y
0
Nope, not 1 single error and the weird thing is if I make 1 of them true both of them are true PullAnAllNighter 8 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

Your problem is that you are setting the value for all of them with the value from one skin. The best way to fix this is to use a table in a fashion somewhat like this:

local Storage = game:GetService('DataStoreService'):GetDataStore('SkinsHolder')

game.Players.PlayerAdded:Connect(function(player)
    local skins = game.ServerStorage.Lazors:Clone();
    skins.Parent = player;
    local savedskins = Storage:GetAsync(player.UserId .. "-Skins");
    if savedskins == nil then
                warn("Data not found");
        else
        for i,v in pairs(skins:GetChildren()) do
            v.Value = savedskins[i]; 
        end;
    end;
end);

game.Players.PlayerRemoving:connect(function(player)
    local id = player.UserId;
    local skins = {};
    for i,v in pairs(player.Lazors:GetChildren()) do
        table.insert(skins, i, v.Value); -- This inserts into the skins table and sets the value of v to i (the index of the object)
    end;
    Storage:SetAsync(id.. "-Skins", skins);
end);

I hope this helped. If it did please accept this as the answer. If you are still confused or just need help with other scripts feel free to message me and ask.

Ad

Answer this question