https://www.roblox.com/library/538721858/Global-Leaderboard
I have this free model that I'm trying to make work with my script but I'm not sure how it works, here's the script in it
local ds = game:GetService("DataStoreService")
local ods = ds:GetDataStore("timesavesystem")
function updateBoard(board, data)
for k,v in pairs(data) do
local pos = k
local name = v.key
local score = v.value
local nametextbox = board.SurfaceGui:FindFirstChild("Name" .. pos)
nametextbox.Text = name
local scoretextbox = board.SurfaceGui:FindFirstChild("Score" .. pos)
scoretextbox.Text = score
end
end
while true do
-- wrap logic in pcall in case datastore request fails
local success, message = pcall(function()
local pages = ods:GetSortedAsync(false, 5)
-- get data for first board
local data = pages:GetCurrentPage()
updateBoard(game.Workspace.Top5ScoreBoard, data)
-- check if another page of data exists
if not pages.IsFinished then
-- if so then get data for second board
pages:AdvanceToNextPageAsync()
data = pages:GetCurrentPage()
updateBoard(game.Workspace.Next5ScoreBoard, data)
end
end)
if not success then
print(message)
end
wait(60)
end
heres the datastorage in my script
-- services
local plrServ = game:GetService("Players")
local badgeService = game:GetService("BadgeService")
local datastore = game:GetService("DataStoreService")
local ds = datastore:GetDataStore("timesavesystem")
-- var
local badgeId = 2100422700
local badge2Id = 2100404188
local badge3Id = 2100402260
plrServ.PlayerAdded:connect(function(plr)
local Stats = Instance.new("Model")
Stats.Name = "leaderstats"
local Timer = Instance.new("IntValue")
Timer.Name = "Time"
Timer.Parent = Stats
Stats.Parent = plr
Timer.Value = ds:GetAsync(plr.UserId) or 0
Timer.Changed:Connect(function()
ds:SetAsync(plr.UserId, Timer.Value)
game.Players.PlayerRemoving:Connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Time.Value)
end)
end)
