I have used a tutorial for this, I also made an additional leaderboard, this is for a speedrun game and you need the fastest times (mainly top 8) to make it to the leaderboard, but the leaderboard appears to be empty, here is my script:
wait(5) local ds = game:GetService("DataStoreService") local ts = ds:GetOrderedDataStore("Time") local function update() print("leaderboard updated") local y, n = pcall(function() local data = ts:GetSortedAsync(true, 8) local page = data:GetCurrentPage() for rank, Data in pairs(page) do local username = game.Players:GetPlayerByUserId(tonumber(Data.key)) local name = username local bestTime = Data.Value local onLeaderboard = false for i,v in pairs(script.Parent.Frame.List.ListContent:GetChildren()) do if(v.Player.Text == name)then onLeaderboard = true end if bestTime and not onLeaderboard then local sample = script.Sample:Clone() sample.Username = name sample.Value = bestTime sample.Number = rank sample.Position = UDim2.new(0,0,sample.Position.Y.Scale + (.08 * #script.Parent.Frame.List.ListContent:GetChildren()), 0) sample.Parent = script.Parent.Frame.List.ListContent end end end end) if n then print("YOU FAIL!!!!!!") end end update() while wait(60) do for _,plr in pairs(game.Players:GetPlayers()) do local pb = plr.leaderstats["Best Time"].Value * 100 local data = ts:SetAsync(plr.UserId, pb) end for _,fra in pairs(script.Parent.Frame.List.ListContent:GetChildren()) do fra:Destroy() end update() end
Thank you for any help in advance