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

How do I create a sequenced ordered data store leaderboard?

Asked by 6 years ago
Edited 6 years ago

Hello,

Recently, I have created a leaderboard script in ServerScriptService for my game. It controls creating a stage, cash and wins leaderboard, which works great using DataStore2 :)

I have had a couple of issues on a part of this leaderboard, the ordered data store part.

Firstly, it does not order the wins in a high to low order. It has sequenced the players in a 'last updated' order.

For example:

What my leaderboard is showing:

https://cdn.discordapp.com/attachments/356675974928007168/518192064706379787/unknown.png

What I'm trying to get it to show:

https://cdn.discordapp.com/attachments/356675974928007168/518192333758398535/example.png

Secondly, I am having issues where the leaderboard doesn't appear at all. But then other times it appears. I think it is because ROBLOX has troubles with data stores ATM. That's why I switched to DataStore2 on standard data stores. If that is the answer to the problem, how do I use my ordered data store on the DataStore2 system?

This is an example on the leaderboard not appearing:

https://cdn.discordapp.com/attachments/356675974928007168/518193965791576092/unknown.png

This is the DataStore2 module and system:

Module: https://www.roblox.com/library/1936396537/DataStore2-Data-Loss-Prevention-and-Caching

Description: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317

This is my current code for the leaderboard script in ServerScriptStorage:

The parts of the code that is relevant to the ordered data store leaderboard are lines 1-52.

001local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule"))
002local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("WinsFixed")
003local Pages = ODS:GetSortedAsync(false,10)
004local Data = Pages:GetCurrentPage()
005local GUI1=game.StarterGui.LeaderboardUI
006local GUI2=game.StarterGui.LeaderboardUI1
007 
008local function Update()
009    local succ,err = pcall(function()
010        local Template = GUI1.Template
011            for i,v in pairs(GUI1.MainFrame:GetChildren()) do
012                if v:IsA("Frame") then
013                    v:Destroy()
014                end
015            end
View all 178 lines...

Any advice you can give will be appricated.

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Hello,

I have asked a couple of roblox scripting pros about this. They said this: First of all, they don't think ordered data stores are compatible with DataStore2.

Secondly, the reason why the leaderboard doesn't appear all the time is that the script is needed to include a new pcall function. As shown in the script.

Thirdly, the reason why the leaderboard isn't displaying in the correct order is that the UiListLayout of the actual UI has been setup incorrectly. These are the correct settings for my leaderboard:

https://cdn.discordapp.com/attachments/356675974928007168/524317164220579843/unknown.png

Another reason why the leaderboard didn't display in the correct order, is that I needed to include a new line of code which ordered the leaderboard, as it updated. Here is the corrected version of the code:

01local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule"))
02local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("WinsFixed")
03local GUI1=game.StarterGui.LeaderboardUI
04local GUI2=game.StarterGui.LeaderboardUI1
05 
06local function load()
07    local succ,err = pcall(function()            --New pcall function
08        warn("Successfully loaded the leaderboard")
09        local Pages = ODS:GetSortedAsync(true,10)
10        local Data = Pages:GetCurrentPage()
11        local Template = GUI1.Template
12 
13        for i,v in pairs(GUI1.MainFrame:GetChildren()) do
14            if v:IsA("Frame") then
15                v:Destroy()
View all 47 lines...

I have got rid of the 'Update' function and joined the two functions together for simplicity. Hope this helps.

0
Thanks for replying to yourself, I am now finding this useful. TomsGames 225 — 5y
Ad

Answer this question