I am trying to make global leaderboard, but its not working
local DataStoreService = game:GetService("DataStoreService")
local Store = DataStoreService:GetOrderedDataStore("Money")
local T = {"K","M","B","T","q","Q","s","S","O","N","d","U","D"}
local function roundNumber(n)
if not tonumber(n) then return n end
if n < 10000 then return math.floor(n) end
local d = math.floor(math.log10(n)/3)*3
local s = tostring(n/(10^d)):sub(1,5)
return s.." "..tostring(T[math.floor(d/3)])
end
local function updateLeaderboard()
local succses, err = pcall(function()
warn("1")
local Data = Store:GetSortedAsync(false,10)
local StorePage = Data:GetCurrentPage()
for Rank,data in ipairs(StorePage) do -- loop is not starthing
warn("2")
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local neederData = data.Value
local isOnLeaderboard = false
for i,v in pairs(script.Parent.Main.SurfaceGui.ScrollingFrame:GetChildren()) do
if v.name == userName then
isOnLeaderboard = true
warn("Already on leaderboard")
break
end
end
if neederData and isOnLeaderboard == false then
local newFrame = script.Template:Clone()
newFrame.Name = userName
newFrame.PlayerName.Text = userName
newFrame.ValueOfValue.Text = roundNumber(neederData)"$"
warn("4")
end
end
end)
if not succses then
warn(err)
end
end
game.Players.PlayerRemoving:Connect(function(player)
if script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name) then
script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name):Destroy()
end
end)
while wait(5) do -- i put 5 sec for a test
warn("Starting")
updateLeaderboard()
end
My problem is for loop on line 20 is not starting.
You forgot to concatenate the “$” and also to set the parent at the end:
local DataStoreService = game:GetService("DataStoreService")
local Store = DataStoreService:GetOrderedDataStore("Money")
local T = {"K","M","B","T","q","Q","s","S","O","N","d","U","D"}
local function roundNumber(n)
if not tonumber(n) then return n end
if n < 10000 then return math.floor(n) end
local d = math.floor(math.log10(n)/3)*3
local s = tostring(n/(10^d)):sub(1,5)
return s.." "..tostring(T[math.floor(d/3)])
end
local function updateLeaderboard()
local succses, err = pcall(function()
warn("1")
local Data = Store:GetSortedAsync(false,10)
local StorePage = Data:GetCurrentPage()
for Rank,data in ipairs(StorePage) do -- loop is not starthing
warn("2")
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local neederData = data.Value
local isOnLeaderboard = false
for i,v in pairs(script.Parent.Main.SurfaceGui.ScrollingFrame:GetChildren()) do
if v.name == userName then
isOnLeaderboard = true
warn("Already on leaderboard")
break
end
end
if neederData and isOnLeaderboard == false then
local newFrame = script.Template:Clone()
newFrame.Name = userName
newFrame.PlayerName.Text = userName
newFrame.ValueOfValue.Text = roundNumber(neederData) .."$"
newFrame.Parent = script.Parent.Main.SurfaceGui.ScrollingFrame
end
end
end)
if not succses then
warn(err)
end
end
game.Players.PlayerRemoving:Connect(function(player)
if script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name) then
script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name):Destroy()
end
end)
while wait(5) do -- i put 5 sec for a test
warn("Starting")
updateLeaderboard()
end
I don’t know seems that you even followed Roblox’s guide on DataStorePages but you are not advancing to the next page and are you sure that the data store is not empty?