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

How can I keep leaderboard stats in different places?

Asked by 10 years ago

I have different ROBLOX places connected through one game, and I would like to know how to keep the leaderboard stats of players in the different games.

Thank you.

1 answer

Log in to vote
0
Answered by
Tecara 0
10 years ago

As long as you already have a leaderboard script that sets up the leaderboard in each game, this will carry the leaderboard data to each one. So just make sure that each place has a 1- a leaderboard script, 2- this script. Tell me if you have any problems.

--[[Savin'
        Dem
            Stats   
--]]
game.Players.PlayerRemoving:connect(function(player)
    local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i =  1, #statstorage do
    datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
    print("saved data number "..i)

end
print("Stats successfully saved")   
end)


--[[
    Loadin'
        Dem
            Stats
--]]
game.Players.PlayerAdded:connect(function(player)
        local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

    player:WaitForChild("leaderstats")
    wait(1)
    local stats = player:FindFirstChild("leaderstats"):GetChildren()
    for i = 1, #stats do            
    stats[i].Value = datastore:GetAsync(stats[i].Name)
    print("stat numba "..i.." has been found")
        end
end)
0
May I ask what the "1-" and "2-" represent? I'm very new to advanced scripting, very sorry if this sounds "newbie." DrCylonide 158 — 10y
0
This didn't work.. any suggestions? DrCylonide 158 — 10y
Ad

Answer this question