Hello!
So, I started using DataStore2 (Post: How to use DataStore2 - Data Store caching and data loss prevention)
I want to make global leaderboard with rebirths and time spent in the game.
Everything works fine (DataStore2), but I don’t know, how would I make global leaderboard with ordered datastore.
I was watching a YT tutorial about it and some code, but I didn’t get it to work (which is obvious). So, basically. Is there any way to do it? I really want to have global leaderboard and keep DataStore2.
Here’s the script, I have right now:
local DataStore2 = require(game.ServerScriptService.DataStore2)
for i = 1, 10 do
local Sam = script.Sample:Clone()
Sam.Name = i
Sam.Parent = script.Parent.Frame.Leaderboard
Sam.UserPos.Text = tostring(i)
Sam.score.Text = "nil"
Sam.UserName.Text = ""
Sam.LayoutOrder = i
end
function updateGui()
for i,v in pairs(game.Players:GetChildren()) do
local DataStoreTimegame:GetService("DataStoreService"):GetOrderedDataStore("TimeLeaderboard")
local timeData = DataStore2("Time", v)
local Data = 1
DataStoreTime:SetAsync(v.UserId,Data)
end
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("TimeLeaderboard")
local Pages = DataStore:GetSortedAsync(false,10)
local Data = Pages:GetCurrentPage()
for k,v in pairs(Data) do
if tonumber(v.key) >= 1 then
local frame = script.Parent.Frame.Leaderboard:FindFirstChild(tostring(k))
if frame then
frame.UserName.Text = game.Players:GetUserIdFromNameAsync(v.key)
frame.score.Text = tostring(v.Value)
end
end
end
end
while true do
updateGui()
wait(2)
end
Thank you!