When I have managed to solve this problem I will put it in the form of a GlobalLeaderboard.
-- << Services >> --
local DataStoreService = game:GetService("DataStoreService")
-- << Variables >> --
local data_Donations = DataStoreService:GetOrderedDataStore("DonationsScore")
-- << Functions >> --
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = data_Donations:GetSortedAsync(false, 10)
local topTEN = Data:GetCurrentPage()
for rank, data in ipairs(topTEN) do
local name = data.key
local score = data.Value
print(name.." is ranked #"..rank.." with "..score.."score")
end
end)
if not success then
print(errorMessage)
end
end
-- << Connect >> --
while true do
updateLeaderboard()
print("Updated!")
wait(10) -- Temp
end
I have no errors but nothing happens, maybe the data is not recognised? I don’t understand it very well
Thanks!
An example that I use: - Refreshes every 20 seconds
-- >> Variable/Services << --
local PrestigeODS = game:GetService("DataStoreService"):GetOrderedDataStore("YOURDATA")
-- >> Script << --
local function Handler()
local Success, Err = pcall(function()
local Data = PrestigeODS:GetSortedAsync(false, 15)
local PrestigePage = Data:GetCurrentPage()
for Rank, Data in ipairs(PrestigePage) do
local Name = Data.key
local Prestige = Data.value
local NewObj = game.ReplicatedStorage:WaitForChild("lbFrame"):Clone()
NewObj.Player.Text = Name
NewObj.TotalWheat.Text = Prestige
NewObj.Rank.Text = "#"..Rank
NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.08 * #game.Workspace.GlobalLeaderboard2.lbGUI.Holder:GetChildren()), 0)
NewObj.Parent = game.Workspace.GlobalLeaderboard2.lbGUI.Holder
end
end)
if not Success then
error(Err)
end
end
-- >> Loop to refresh << --
while true do
for _,Player in pairs(game.Players:GetPlayers()) do
PrestigeODS:SetAsync(Player.Name, Player.leaderstats.YOURDATA.Value)
end
for _,v in pairs(game.Workspace.GlobalLeaderboard2.lbGUI.Holder:GetChildren()) do
if v.Name == "lbFrame" then
v:Destroy()
end
end
Handler()
wait(20) --Time until Refresh
end
This is the same thing that i have, you just have the system for include a leaderboard,
my problem is that without or with this doesn’t work, and i don’t know why, my data seems to be correct…
I tried assigning test values to my DataStores and it managed to get a value out.
The problem comes from my DataStores but I don’t really understand why.
I’m using my DataStores for the leaderboard, the value is stored in the player thanks to another script.
Here is the script for the leaderboard (with the test values):
-- << Services >> --
local DataStoreService = game:GetService("DataStoreService")
-- << Variables >> --
local data_Donations = DataStoreService:GetOrderedDataStore("DonationsScore")
-- << Functions >> --
data_Donations:SetAsync("Mars", 19) --Temporary
data_Donations:SetAsync("Marss", 1058) --Temporary
data_Donations:SetAsync("Marssss", 234) --Temporary
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = data_Donations:GetSortedAsync(false, 10)
local topTEN = Data:GetCurrentPage()
for rank, data in ipairs(topTEN) do
local name = data.key
local score = data.Value
print(name.." is ranked #"..rank.." with "..score.."score")
end
end)
if not success then
print(errorMessage)
end
end
-- << Connect >> --
while true do
updateLeaderboard()
print("Updated!")
wait(10) -- Temp
end
And here is the script that manages the dataStores: