Script won't Clone the right Frame

So I’ve just made this global leaderboard for my hangout game, and a script to go along with it, but my issue is that my script is duplicating the wrong frame.

Whenever I run the game, it keeps duplicating the TopBar instead of PlayerRank. I tried to re-name it to be the top one so it selects that other than the TopBar, but it didn’t work.

Could anyone help with this? Here is the script along with screenshots:

-- // Script Services
local DataStoreService = game:GetService("DataStoreService")
local TimeData = DataStoreService:GetOrderedDataStore("TimeData-dev")

-- // Script Gui
local Gui = script.Parent.Leaderboard
local Rank = Gui.PlayerRank
local List = Gui.PlayerList

-- // Script Functions
local function SavePlayerData()
	for _, player in pairs(game:GetService("Players"):GetPlayers()) do
		local minutes = player.leaderstats.Minutes

		local playerKey = "id_"..player.UserId.."_minutes"
		local success, result = pcall(function()
			return TimeData:SetAsync(playerKey, minutes.Value)
		end)

		if not success then
			warn("⚠ | "..result)
		end
	end
end

local function getTop50Players(player)
	local isAscending = false
	local pageSize = 50
	local pages = TimeData:GetSortedAsync(isAscending, pageSize)
	local top50 = pages:GetCurrentPage()
	
	local top = {}
	
	for rank, entry in pairs(top50) do
		local dataKey = entry.key
		local userId = dataKey:match("id_(%d+)_minutes")
		local playerName = game:GetService("Players"):GetNameFromUserIdAsync(tonumber(userId))
		local minutes = entry.value

		local currentPlayer = { Player = playerName, Minutes = minutes, Rank = rank }
		table.insert(top, rank, currentPlayer)
	end
	
	return top
end

local function ClearLeaderboard()
	task.spawn(function()
		for _, plrFrame in pairs(List:GetChildren()) do
			if not plrFrame:IsA("Frame") then continue end
			plrFrame:Destroy()
			task.wait(0.25)
		end
	end)
end

local function UpdateLeaderboard()
	SavePlayerData()
	ClearLeaderboard()
	local top50 = getTop50Players()
	
	task.spawn(function()
		for _, plr in ipairs(top50) do
			local frame = Rank:Clone()
			frame.Parent = List
			
			frame.Player.Text = tostring(plr.Player)
			frame.Minutes.Text = tostring(plr.Minutes)
			frame.Rank.Text = tostring(plr.Rank)
			
			frame.Visible = true
			task.wait(0.25)
		end
	end)
end

-- // Script
task.spawn(function()
	while true do
		UpdateLeaderboard()
		for count=60,0,-1 do
			script.Parent.UpdateMessage.Updater.Message.Text = "Updating in.. "..count
			task.wait(1)
		end
	end
end)

This is the frame that keeps getting duplicated.

This is the frame that I want to be duplicated.

EDIT 1
It is duplicating the right frame, but the scrolling frame is scaling it weirdly. Anyone able to fix that?

1 Like

Can you double-check if it’s cloning the correct object by looking within the children of the UI and checking the name? It might just be the scrolling frame scaling it weirdly.

1 Like

It is cloning the right item, but how do I fix this scaling issue now?

You would need to mess around with the sizes and properties of the scrolling frame and the template frame until you like how it looks

2 Likes

Okay, thank you for helping me!

1 Like

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