I've made a Global Leaderboard but nothing is showing! SOLUTION FOUND!

I’ve made a Global Leaderboard but if it updates nothing shows on it so i wanted to ask if anybody could help me since there was another topic but the person sound the solution by its self so im asking here again! would be nice if i could get a quick response :grinning::eyes:

here my code:

local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")

local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = WinsLeaderboard:GetSortedAsync(false, 5)
		local WinsPage = Data:GetCurrentPage()
		for Rank, data in ipairs(WinsPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Wins = data.Value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
			
			if Wins and isOnLeaderboard == false then
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
				newLbFrame.Player.Text = Name
				newLbFrame.Wins.Text = Wins
				newLbFrame.Rank.Text = "#"..Rank
				newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
			end
		end
	end)
	if not success then
		print(errorMessage)
	end
end

while true do 
	

	for _, player in pairs(game.Players:GetPlayers()) do
		WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
	end
	
	for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
		frame:Destroy()	
	end
	
	updateLeaderboard()
	print("Updated!")
	
	wait(10)
end

it would be nice if you could send the fixed code when you may help me :smile::smile:
image
no errors btw ^^^

2 Likes

Are there any errors? Are you testing in studio or roblox client? If you are on studio you have to turn on API services. Also, can you print out Rank and data in your loop? You also have to use pairs instead of ipairs.

1 Like

I think maybe because you IsOnLeaderboards variable to be false, this happens. Also, can you give a brief of why you added this variable?

1 Like

so I used the tutorial (made by TheDevKing) since im not good at scripting and he said to add it and i just followed the steps

1 Like

there arent any errors and everything on studio is activated (only third party teleports is disabled) and imma change ipairs to pairs and try then!

1 Like

Hmm, but what he said about this variable like the reason to add this?

i dont know let me check into the video he made and see what he says.

Update: he didnt say anything abt this vabriable

Alr, surely take your time. My best guess is to remove that variable because from looking at the way this variable is used, I’m assuming that it’s just for checking if player is in leaderboards or not, but you don’t really need to check it.

Edit -

Hmm, then just remove the condition and this variable. I will send the code in a moment like how am I saying

what do you mean by printing out rank and data?

local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")

local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = WinsLeaderboard:GetSortedAsync(false, 5)
		local WinsPage = Data:GetCurrentPage()
		for Rank, data in ipairs(WinsPage) do
print(Rank, data) --he means to add this line
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Wins = data.Value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
			
			if Wins and isOnLeaderboard == false then
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
				newLbFrame.Player.Text = Name
				newLbFrame.Wins.Text = Wins
				newLbFrame.Rank.Text = "#"..Rank
				newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
			end
		end
	end)
	if not success then
		print(errorMessage)
	end
end

while true do 
	

	for _, player in pairs(game.Players:GetPlayers()) do
		WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
	end
	
	for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
		frame:Destroy()	
	end
	
	updateLeaderboard()
	print("Updated!")
	
	wait(10)
end

let me test if this works now if so it would really help :grinning:

1 Like
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")

local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = WinsLeaderboard:GetSortedAsync(false, 5)
		local WinsPage = Data:GetCurrentPage()
		for Rank, data in ipairs(WinsPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Wins = data.Value
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
				newLbFrame.Player.Text = Name
				newLbFrame.Wins.Text = Wins
				newLbFrame.Rank.Text = "#"..Rank
				newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
	end
end)
	if not success then
		print(errorMessage)
	end
end

while true do 
	

	for _, player in pairs(game.Players:GetPlayers()) do
		WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
	end
	
	for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
		frame:Destroy()	
	end
	
	updateLeaderboard()
	print("Updated!")
	
	wait(10)
end

it gives me this right here:
image

this script doesnt work aither sadly :slightly_frowning_face::slightly_frowning_face: thats the output it gives me:

@Moneypro456789 Are you still there? May you look at what it prints and its still not working!

1 Like

I’ve now fixed it by my self thank you for helping tho :slight_smile:

1 Like

```local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")

local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = WinsLeaderboard:GetSortedAsync(false, 5)
		local WinsPage = Data:GetCurrentPage()
		for Rank, data in ipairs(WinsPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Wins = data.Value
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
				newLbFrame.Player.Text = Name
				newLbFrame.Wins.Text = tostring(Wins)
				newLbFrame.Rank.Text = "#"..tostring(Rank)
				newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
	end
end)
	if not success then
		print(errorMessage)
	end
end

while true do 
	

	for _, player in pairs(game.Players:GetPlayers()) do
		WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
	end
	
	for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
		frame:Destroy()	
	end
	
	updateLeaderboard()
	print("Updated!")
	
	wait(10)
end

@Moneypro456789 thank you but ive not got it fixed but i need help at another globale leaderboard because there is nothing showing up AGAIN. this time the lobal leaderboard is a global death leaderboard

here is the code:

local DataStoreService = game:GetService("DataStoreService")
local DeathsLeaderboard = DataStoreService:GetOrderedDataStore("DeathsLeaderboard")

local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = DeathsLeaderboard:GetSortedAsync(false, 5)
		local DeathsPage = Data:GetCurrentPage()
		for Rank, data in ipairs(DeathsPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Deaths = data.value
			local isOnLB = false
			for i, v in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLB = true
					break
				end
			end
			
			if Deaths and isOnLB == false then
				local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameDeaths"):Clone()
				newLBFrame.Player.Text = Name
				newLBFrame.Deaths.Text = Deaths
				newLBFrame.Rank.Text = "#"..Name
				newLBFrame.Position = UDim2.new(0, 0, newLBFrame.Position.Y.Scale + (.1 * game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
				newLBFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder
			end
		end
	end)
	
	if not success then
		print(errorMessage)
	end
end

while true do
	
	for _, player in pairs(game.Players:GetPlayers()) do
		DeathsLeaderboard:SetAsync(player.UserId, player.leaderstats.Deaths.Value)
	end
	
	for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLeaderboard()
	print("Updated!")
	
	wait(10)
end

if i made any mistakes tell me or fix them if possible :slight_smile:

Hmm, just copy the fixed code you had for WinsLeaderboard, and just change the Datastore name to DeathsLeaderboard

i’ve already found a solution but thank you :smile:

1 Like