leaderstats, money datastore is saving but points data store is not saving,
so Money DataStore works, But Points DataStore does not work, why?
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("Money")
local DS2 = DSS:GetDataStore("Points")
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
local Money = Instance.new("IntValue")
Money.Parent = ls
Money.Name = "Money"
Money.Value = DS:GetAsync(plr.UserId) or 0
local Points = Instance.new("IntValue")
Points.Parent = ls
Points.Name = "Points"
Points.Value = DS2:GetAsync(plr.UserId) or 0
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync(plr.UserId, plr.leaderstats.Money.Value)
DS2:SetAsync(plr.UserId, plr.leaderstats.Points.Value)
end)
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
DS2:SetAsync(v.UserId, v.leaderstats.Points.Value)
end
end)
Keep in mind that it increases the number cap from 9.1 quintillion all the way to 10 to the power of 308.
And unlike IntValue, if it reaches he number cap then it will return inf (short for infinite, you can use math.huge to compare a number between infinite) and not negative.
In the for loop located in game:BindToClose(), you’ve only made the DS2 data store save (via :SetAsync()).
The solution is to also save the DS data store in it, reason why it didn’t work before is because game:CloseToBind() is like game.Players.PlayerRemoving, but it only executes when the server shuts down which is what happens in roblox studio.
So now the game:BindToClose() script should look like this:
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
DS2:SetAsync(v.UserId, v.leaderstats.Points.Value)
DS:SetAsync(plr.UserId, plr.leaderstats.Money.Value)
end
end)
I would recommend putting a print statement after saving the two data stores in your PlayerRemoving event to make sure that both data stores claimed to have saved before the event ended since the player got removed.
If the player leaves before that script can grab the ID, chances are it won’t save, and could even be throwing an error.
Test this with two players on an actual server with HTTP requests enabled to true. Have your alt account be the one that leaves so you can see server console.