Hi, I'm trying to make it save 2 IntValues in leaderstats. I've gotten it to save points, but not gems. What am I doing wrong? Thanks
local DSService = game:GetService("DataStoreService"):GetDataStore("SaveStats")
game.Players.PlayerAdded:connect(function(player)
-- Define variables
local uniquekey = "id-"..player.userId
local leaderstats = Instance.new("IntValue", player)
local points = Instance.new("IntValue")
local gems = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
points.Parent = leaderstats
points.Name = "Points"
gems.Parent = leaderstats
gems.Name = "Gems"
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
points.Value = GetSaved[1]
gems.Value = GetSaved[2]
else
DSService:SetAsync(uniquekey, points.Value, gems.Value)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local uniquekey = "id-"..player.userId
local pointtable = {player.leaderstats.Points.Value}
local gemtable = {player.leaderstats.Gems.Value}
DSService:SetAsync(uniquekey, pointtable, gemtable)
end)

1 comment
you can only save one value per SetAsync, so you either do SetAsync(UniqueKey,{Pointtable,Gemtable}), or you do two SetAsyncs. (I recommend the first one.)