How can I make certain ranks background color's on this leaderboard?

Hey everyone! I am trying to figure out how to make this global leaderboard have gold for #1, #2 silver, #3 bronze and everyone else white. I have tried various different techniques though for some reason I can’t get it to work.

The leaderboard takes information from datastorage and puts on the leaderboard, updates every 60 seconds. robloxapp-20200731-1542258.wmv (67.9 KB)


The setup:
image
Here’s my code, please note that this was from a tutorial:

local DataStoreService = game:GetService("DataStoreService")
local TimeLB = DataStoreService:GetOrderedDataStore("TimeSaveSystem")

local function updateLB()
	local success, errorMessage = pcall(function()
		local Data = TimeLB:GetSortedAsync(false, 5)
		local TimePage = Data:GetCurrentPage()
		for Rank, data in ipairs(TimePage) do
			local UserName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = UserName
			local Mins = data.value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
			
			if Mins and isOnLeaderboard == false then
				local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLBFrame.Player.Text = Name
				newLBFrame.Minutes.Text = Mins
				newLBFrame.Rank.Text = "#"..Rank
				newLBFrame.Position = UDim2.new(0, 0, newLBFrame.Position.Y.Scale + (.1 * #game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
				newLBFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder
				
			end
		end
	end)
	if not success then
		print(errorMessage)
	end
end

while true do
	
	for _, player in pairs(game.Players:GetPlayers()) do
		TimeLB:SetAsync(player.UserId, player.leaderstats.Minutes.Value)
	end
	
	for _, frame in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLB()
	print("Updated leaderboard")
	wait(60)
end

Hi, if you don’t understand the code then you aren’t really learning. What I’d do is find the code that gets the rank and puts it in the text, and then make it so checks it’s value, and sets it’s color based on that.

Like @TheWorstOne_2 said, when you clone the frame, check if the player’s rank is for example 1 and if yes, change the BackgroundColor.

1 Like