So I'm trying to save at least 4 value/ leaderstats in my game, but I found out that when I played, it only saves the first 2 stats, the other 2 stats didn't save.
Script:
local DSService = game:GetService("DataStoreService"):GetDataStore("Stage4")
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
leaderstats.Name = "leaderstats"
local Stage = Instance.new('IntValue',leaderstats)
Stage.Name = "Stage"
Stage.Value = 0
local Gems = Instance.new("NumberValue",leaderstats)
Gems.Name = "Gems"
Gems.Value = 0
local Skip = Instance.new("NumberValue",plr)
Skip.Name = "Skip"
Skip.Value = 0
local StageSkipped = Instance.new("NumberValue",leaderstats)
StageSkipped.Name = "StageSkipped"
StageSkipped.Value = 0
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
Stage.Value = GetSaved[1]
Gems.Value = GetSaved[2]
StageSkipped.Value = GetSaved[3]
else
local NumbersForSaving = {Stage.Value, Gems.Value, StageSkipped.Value, Skip.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Stage.Value, plr.leaderstats.Gems.Value, plr.leaderstats.StageSkipped.Value, plr.Skip.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
I don't think there is anything wrong with it, just that it wouldn't save the last 2 values/stats. Any help would be appreciated. Thanks!

2 comments
Im having a similar issue with my datastore, but the script is quite a bit bigger. hopefully you figure it out.
in answer to your question yes i believe so but you are WELL below that threshhold