Hi guys!
This is an ordered datastore leaderboard. It works occasionally and I'm not sure why. Sometimes it updates and sometimes it doesn't (save/load?)
I am trying to make it compatible with name-changing by saving user Id's and I'm trying to get it to auto-update every 2 minutes.
I get no errors.
Any ideas?
Thanks! :)
local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("Escapes")
local pages = ODS:GetSortedAsync(false, 10)
local Count = 0
local Gui = script.Parent
function Leaderboard()
Count = 0
local data = pages:GetCurrentPage()
for i,item in next, (data) do
Count = Count + 1
local Board = Gui:FindFirstChild("Place"..Count.."")
if string.match(item.key, "^%d+$") then
name = game.Players:GetNameFromUserIdAsync(tonumber(item.key))
Board.PName.Text = name
else
Board.PName.Text = item.key
end
Board.Score.Text = item.value
if Count == 10 then
return
end
end
end
while true do
local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("Escapes")
local pages = ODS:GetSortedAsync(false, 10)
local Count = 0
local Gui = script.Parent
Leaderboard()
wait(120)
end
function PlayerLeaving(Player)
ODS:SetAsync(Player.userId, Player.leaderstats.Escapes.Value)
end
game.Players.PlayerRemoving:connect(PlayerLeaving)
