Global Leaderboard in my game is not working

I want to use a global leaderboard for my game, but every time i start up the game, the only one on the global leaderboard is the richest person, BUT! the thing that bothers me is that i tried printing the result print(topTen) and it resulted all the data including the other people that aren’t that rich, but on the leaderboard still nothing… I tried many things AdvanceToNextPageAsync, tables and more, even tried other leaderboards but nothing, still the same result.

–local DataStore = game:GetService(“DataStoreService”)
–local StatsDataStore = DataStore:GetOrderedDataStore(“J1BEV56415”) --Make It Hard So Hacker Cant Guess It

local DataStoreService = game:GetService(“DataStoreService”)
local PointsODS = DataStoreService:GetOrderedDataStore(“MoneyGL”)

local ResetTime = script.Parent.TimeUntilReset
local Time = script.Parent.Time.Value
Time = 8
while wait(1) do

Time = Time - 1 
script.Parent.Parent.ResetTime.TextLabel.Text = "Resetting in " .. Time .. " seconds..."

if Time == 0 then Time = ResetTime.Value
	for i, plr in pairs(game.Players:GetChildren()) do	
		wait()
		PointsODS:SetAsync(plr.UserId, plr.leaderstats:FindFirstChild("Money").Value) 
		print(plr.Name.." added.")
	end

	for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
		if leaderboardRank.ClassName == "Frame" then
			leaderboardRank:Destroy()
		end
	end
	
	local success, errorMsg = pcall(function()
		
		local pages = PointsODS:GetSortedAsync(false, 15)
		local topTen = pages:GetCurrentPage()
		
		print(topTen)
		
		for i,v in pairs(topTen) do
			print(game.Players:GetNameFromUserIdAsync(tonumber(v.key)))

			local name = game.Players:GetNameFromUserIdAsync(tonumber(v.key))
			local id = tonumber(v.key)
			local statsname = v.value
			wait(0.1)

			local Gui = script.Top:Clone()

			Gui.PlrName.Text = name

			Gui.Rank.Text = "#" .. i

			Gui.Amount.Text = statsname

			Gui.Parent = script.Parent	

			if Gui.Rank.Text == "#1" then
				Gui.Color.Value = Color3.fromRGB(255, 255, 0) --Top 1 Background Color
				script.Parent.Parent.Parent.Parent.Top1.Configuration.userId.Value = id
				script.Parent.Parent.Parent.Parent.Top1.Tags.Container.pName.Text = name
			end
			if Gui.Rank.Text == "#2" then
				Gui.Color.Value = Color3.fromRGB(98, 98, 98) --Top 2 Background Color
				script.Parent.Parent.Parent.Parent.Top2.Configuration.userId.Value = id
				script.Parent.Parent.Parent.Parent.Top2.Tags.Container.pName.Text = name
			end
			if Gui.Rank.Text == "#3" then
				Gui.Color.Value = Color3.fromRGB(255, 85, 0) --Top 3 Background Color
				script.Parent.Parent.Parent.Parent.Top3.Configuration.userId.Value = id
				script.Parent.Parent.Parent.Parent.Top3.Tags.Container.pName.Text = name	
			end
		end
		
		--[[
		--local data = StatsDataStore:GetSortedAsync(false, 15)
		--local StatsPage = data:GetCurrentPage()


		for i,v in pairs(StatsPage) do

			print(game.Players:GetNameFromUserIdAsync(tonumber(v.key)))

			local name = game.Players:GetNameFromUserIdAsync(tonumber(v.key))
			local id = tonumber(v.key)
			local statsname = v.value
			wait(0.1)

			local Gui = script.Top:Clone()

			Gui.PlrName.Text = name

			Gui.Rank.Text = "#" .. i

			Gui.Amount.Text = statsname

			Gui.Parent = script.Parent	

			if Gui.Rank.Text == "#1" then
				Gui.Color.Value = Color3.fromRGB(255, 255, 0) --Top 1 Background Color
				script.Parent.Parent.Parent.Parent.Top1.Configuration.userId.Value = id
				script.Parent.Parent.Parent.Parent.Top1.Tags.Container.pName.Text = name
			end
			if Gui.Rank.Text == "#2" then
				Gui.Color.Value = Color3.fromRGB(98, 98, 98) --Top 2 Background Color
				script.Parent.Parent.Parent.Parent.Top2.Configuration.userId.Value = id
				script.Parent.Parent.Parent.Parent.Top2.Tags.Container.pName.Text = name
			end
			if Gui.Rank.Text == "#3" then
				Gui.Color.Value = Color3.fromRGB(255, 85, 0) --Top 3 Background Color
				script.Parent.Parent.Parent.Parent.Top3.Configuration.userId.Value = id
				script.Parent.Parent.Parent.Parent.Top3.Tags.Container.pName.Text = name	
			end
		end
		--]]
	end)
end

end

Hello!

Questions

First of all, where are you storing this script?

Second, what is time here? What does it make sense?

Information

Unless hackers reach the server with a RemoteEvent, no need to name the ordered data store hard.


You are saving the data really quickly here. There is a cooldown to save the data.


It is because you are using only two parameters. The actual parameter number is 4.

local notAscending = false
local numberToShow = 100
local minValue = 10
local maxValue  = 10000

local pages = PointsODS:GetSortedAsync(notAscending, numberToShow, minValue, maxValue)

And finally, if this script is in ServerScriptService and you are trying to put the GUI in it, it probably won’t work. Make a specific leaderboard in Workspace and parent the GUI to that leaderboard.

The script is stored in the workspace in the global leaderstats part.
I don’t get your 2nd question, like, you mean like real life time, or some time in the script? please specify.
Even when i put 4 parameters in, still, only the richest person would apper, the others won’t
And the script is a bit messy, so i will clean some parts and post here a better version of it.

local DataStoreService = game:GetService("DataStoreService")
local PointsODS = DataStoreService:GetOrderedDataStore("MoneyGL") 

local ResetTime = script.Parent.TimeUntilReset
local Time = script.Parent.Time.Value
Time = 5
while wait(1) do

	Time = Time - 1 
	script.Parent.Parent.ResetTime.TextLabel.Text = "Resetting in " .. Time .. " seconds..."

	if Time == 0 then Time = ResetTime.Value
		for i, plr in pairs(game.Players:GetChildren()) do	
			wait(1)
			PointsODS:SetAsync(plr.UserId, plr.leaderstats:FindFirstChild("Money").Value) 
		end

		for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
			if leaderboardRank.ClassName == "Frame" then
				leaderboardRank:Destroy()
			end
		end
		
		local success, errorMsg = pcall(function()
			
			local notAscending = false
			local numberToShow = 100
			local minValue = 0
			local maxValue  = 100000000000

			local pages = PointsODS:GetSortedAsync(notAscending, numberToShow, minValue, maxValue)
			local topTen = pages:GetCurrentPage()
						
			for i,v in pairs(topTen) do
				local name = game.Players:GetNameFromUserIdAsync(tonumber(v.key))
				local id = tonumber(v.key)
				local statsname = v.value
				wait(0.1)

				local Gui = script.Top:Clone()

				Gui.PlrName.Text = name

				Gui.Rank.Text = "#" .. i

				Gui.Amount.Text = statsname

				Gui.Parent = script.Parent	

				if Gui.Rank.Text == "#1" then
					Gui.Color.Value = Color3.fromRGB(255, 255, 0) --Top 1 Background Color
					script.Parent.Parent.Parent.Parent.Top1.Configuration.userId.Value = id
					script.Parent.Parent.Parent.Parent.Top1.Tags.Container.pName.Text = name
				end
				if Gui.Rank.Text == "#2" then
					Gui.Color.Value = Color3.fromRGB(98, 98, 98) --Top 2 Background Color
					script.Parent.Parent.Parent.Parent.Top2.Configuration.userId.Value = id
					script.Parent.Parent.Parent.Parent.Top2.Tags.Container.pName.Text = name
				end
				if Gui.Rank.Text == "#3" then
					Gui.Color.Value = Color3.fromRGB(255, 85, 0) --Top 3 Background Color
					script.Parent.Parent.Parent.Parent.Top3.Configuration.userId.Value = id
					script.Parent.Parent.Parent.Parent.Top3.Tags.Container.pName.Text = name	
				end
			end
		end)
	end
end

Why do I want the time you are in now lol? I mean the time variable used in your script.

I understood that you are trying to return the Time’s value to ResetTime. Why not only use this and remove the Time?

while wait(60) do

And here you don’t need to use the Text property. You can just use instead

if tonumber(i) == 1 then

end

Are you sure you have more than 1 player to appear on the leaderboard?

Yes, when i printed the table there were like 8 people data, but the script only read the first one

image

ok, fixed it, i just overlooked something over and over. im just dumb