i cant make the datastore keep the leaderboard values ive been trying all the things i could think of and i even tried watching videos
how to make a datastore with leaderboard?
3 answers
This is how to make a leaderboard: https://www.youtube.com/watch?v=sXpuGnVzsxw
If you want to know more about ordereddatastores go here: https://developer.roblox.com/en-us/api-reference/class/OrderedDataStore
If you need to save more and don't know were to add the extra bits to save more data comment and i'll help you when i'm online!
Ok so I edited it. All of the lines of code with "----" or have "StatName" or both instead of an actual StatName at the end or in the middle of line of code are the example lines of code to add more values to save in the datastore. I hope this helped! If you can mark this answer as the "correct one" i'd appreciate it a lot :) If you still need help on how to figure this out comment back [although i think you should already get it since this is pretty clear]
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.Wins
local save2 = plr.leaderstats."StatName" ----
local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2] ----
else
local NumberForSaving = {save1.Value, save2.Value} ---- ", save2.Value"
ds:GetAsync(plrkey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Wins.Value, plr.leaderstats."StatName".Value})
end)
3 comments
yes please that would bee very helpful if you can help me add more values
Ok, let me add more example values so you can understand how to save more values
I edited the message, hope it's clear now!
local DataStoreService = game:GetService("DataStoreService")
local PointsStore = DataStoreService:GetDataStore("Nameofyoursave")
game.Players.PlayerAdded:Connect(function(Player)
local SavedPoints = PointsStore:GetAsync(Player.UserId)
local Leaderstats = Player:FindFirstChild("leaderstats") or Instance.new("Folder", Player)
Leaderstats.Name = "leaderstats"
local PointsValue = Leaderstats:FindFirstChild("Points") or Instance.new("IntValue", Leaderstats)
PointsValue.Name = "Money"
if SavedPoints ~= nil then
PointsValue.Value = SavedPoints
end
PointsValue.Changed:Connect(function(NewPoints)
PointsStore:SetAsync(Player.UserId, NewPoints)
end)
end)
this is what i use
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
You need to use a ordered datastore