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

Help with saving multiple values?

Asked by 6 years ago

I have a script in the serverscriptservice that is supposed to save peoples data but it doesn't. I have another game where the exact same script does work. Both games have filtering enabled on. This is the script in the game where it doesn't work:

local DSService = game:GetService("DataStoreService")
local DS = DSService:GetDataStore("MyMumIsAVeryPrettyNiceGuy12241")
game.Players.PlayerAdded:Connect(function(plr)
    local uniquekey = "id-" .. plr.userId
    local leaderstats = Instance.new("Folder", plr)
    local savevalueone = Instance.new("IntValue")
    local savevaluetwo = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    savevalueone.Parent = leaderstats
    savevaluetwo.Parent = leaderstats
    savevalueone.Name = "Money"
    savevaluetwo.Name = "Players"
    local data = DS:GetAsync(uniquekey) or {0, 0}   
    savevalueone.Value = data[1] or 0
    savevaluetwo.Value = data[2] or 0
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local uniquekey = "id-" .. plr.userId
    local Savetable = {plr.leaderstats.Money.Value, plr.leaderstats.Players.Value}  
    DS:SetAsync(uniquekey, Savetable)

end)

and here is where it does work

local DSService = game:GetService("DataStoreService")
local DS = DSService:GetDataStore("MyMumIsAVeryPrettyNiceGuy12396")
game.Players.PlayerAdded:Connect(function(plr)
    local uniquekey = "id-" .. plr.userId
    local leaderstats = Instance.new("Folder", plr)
    local savevalueone = Instance.new("IntValue")
    local savevaluetwo = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    savevalueone.Parent = leaderstats
    savevaluetwo.Parent = leaderstats
    savevalueone.Name = "Kills"
    savevaluetwo.Name = "Wins"
    local data = DS:GetAsync(uniquekey) or {0, 0}   
    savevalueone.Value = data[1] or 0
    savevaluetwo.Value = data[2] or 0
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local uniquekey = "id-" .. plr.userId
    local Savetable = {plr.leaderstats.Kills.Value, plr.leaderstats.Wins.Value} 
    DS:SetAsync(uniquekey, Savetable)

end)

What is the difference?

Answer this question