local DataStoreService = game:GetService("DataStoreService")
local leaderstats = DataStoreService:GetDataStore("TEST")
local settings={
groupid = 0
}
game.Players.PlayerAdded:connect(function(player)
local key = "user_"..player.userId
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("IntValue",player)
leaderstats.Name = "leaderstats"
local rank = Instance.new("StringValue", leaderstats)
rank.Name = "Rank"
rank.Value = player:GetRoleInGroup(settings["groupid"])
local points = Instance.new("IntValue", leaderstats)
points.Name = "TEST"
points.Value = points:GetAsync(key)
points.Changed:connect(function() points:SetAsync(key, points.Value) end)
end)
COMMUNITY QUESTION
How come leaderboard stats won't save?
1 answer
Try using this script (Yes I did make it myself.):
local data = game:GetService("DataStoreService"):GetDataStore("TEST")
local settings={
groupid = 0
}
game:GetService("Players").PlayerAdded:connect(function(player)
local key = "user_"..player.UserId
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local rank = Instance.new("StringValue", leaderstats)
rank.Name = "Rank"
rank.Value = player:GetRoleInGroup(settings["groupid"])
local GetPlayerSave = data:GetAsync("user"..player.UserId)
local points = Instance.new("NumberValue", leaderstats)
points.Value = 0
points.Name = "TEST"
if GetPlayerSave then
points.Value = GetPlayerSave[1] or 0
end
end)
game:GetService("Players").PlayerRemoving:connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local ToSave = {leaderstats.TEST.Value}
data:SetAsync("user_"..player.userId, ToSave)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
It still doesn't save when I leave and rejoin a game! Sorry, didn't work.
Oh silly me, I made a mistake. I have edited the script and fixed it. Sorry!
It uh... still doesn't work..
I edited ONCE more.
Yea it's not working, I don't know what's up.