Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to make a datastore with leaderboard?

Asked by 4 years ago

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

0
You need to use a ordered datastore MikkelCircled 42 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

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

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
yes please that would bee very helpful if you can help me add more values Luvaking 0 — 4y
0
Ok, let me add more example values so you can understand how to save more values Nitrolux200 62 — 4y
0
I edited the message, hope it's clear now! Nitrolux200 62 — 4y
Log in to vote
0
Answered by 4 years ago
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

Answer this question