Global Leaderboar doesn't work

Hello! I am making a leaderboard but it doesn’t work. However, it does print well…the print. I need help!

local DSS = game:GetService("DataStoreService")
local ColorLeaderboard = DSS:GetOrderedDataStore("ColorLeaderboard")

local function UpdLeaderboard()
	local success, errormsg = pcall(function()
		local d = ColorLeaderboard:GetSortedAsync(false, 5)
		local ColorPage = d:GetCurrentPage()
		
		for rank, data in ipairs(ColorPage) do
			local UserName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = UserName
			local COlors = data.Value
			local IsOnLeaderboard = false
			
			for i, v in pairs(game.Workspace.leaderboard.LeaderboardGUI.Holder:GetChildren()) do
				if v.Player.Text == Name then
					IsOnLeaderboard = true
					break
				end
				
			end
			if COlors and IsOnLeaderboard == false then
				local NewFrame = game.ReplicatedStorage:WaitForChild("Leaderboard"):Clone()
				
				NewFrame.Player.Text = Name
				NewFrame.Color.Text = COlors
				NewFrame.Rank.Text = "#"..rank
				NewFrame.Position = UDim2.new(0,0, NewFrame.Position.Y.Scale + (.08 * #game.Workspace.leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
				NewFrame.Parent = game.Workspace.leaderboard.LeaderboardGUI.Holder
				
			end
		end
		
	end)
	if not success then
		print(errormsg)
	end
end

while true do
	for _, play in pairs(game.Players:GetPlayers()) do
		ColorLeaderboard:SetAsync(play.UserId, play.leaderstats["🎨 Color"].Value)
		
	end
	
	for _, frame in pairs(game.Workspace.leaderboard.LeaderboardGUI.Holder:GetChildren()) do
		frame:Destroy()
		
	end
	
	UpdLeaderboard()
	print("Updated")
	wait(10)
end

I believe the issue is that you used Value with a capital V instead of value! Let me know if that doesn’t work

1 Like

So should I change all the Value to value?

Yep I think thats the issue!

Basically since you check if COlors it will always return nil and will not run the code to clone the frame because data.Value does not exist!

hmmm that’s weird cause I use Value on leaderstats

Yes leaderstats should be Value but when you use an ordered datastore its value

so to clarify, you should only change Value to value here:

This one is correct:

1 Like

Ah, I see! Sorry haven’t really used Ordered datastore. It’s fixed but, it isn’t on the position it’s supposed to be in.

Are you using a UIGridLayout or UIListLayout for the UI?

If so, you can change the SortOrder to LayoutOrder and then when you clone the frame you can add:

NewFrame.LayoutOrder = i
1 Like

None. Should I use UIListLayout?

I fixed it by changing the offset to 100

1 Like

I usually use a UI Layout but your method of positioning should work although I think using something like

NewFrame.Position = UDim2.new(0,0, (NewFrame.Position.Y.Scale +.08) * i, 0)

would work better than your current solution:

NewFrame.Position = UDim2.new(0,0, NewFrame.Position.Y.Scale + (.08 * #game.Workspace.leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)

The i value is giving me an error.

Sorry that should be rank not i. I didn’t see what loop it was in!

1 Like

Ohhhhhh. Eitherway roblox is down lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.