Help with a custom leaderboard

I’m trying to make a custom leaderboard. It is all updating correctly once, but won’t update after that. The “Updating…” and “updated” messages print, but nothing else. It does not update on the GetPropertyChangedSignal() lines, and there are no errors or warnings in the output.

I’ve tried everything I can, from coroutine to pcall(), to restarting Studio and my whole computer.

Any help is appreciated, I am completely stumped on this one.

local players = game:GetService("Players")
local sGui = game:GetService("StarterGui")

local statsFrame = script:WaitForChild("PlayerStats")
local mainFrame = script.Parent:WaitForChild("MainFrame")
local displayFrame = mainFrame:WaitForChild("PlayersDisplay")

local ranks = {
	["Beginner"] = Color3.fromRGB(77, 77, 77),
	["Rookie"] = Color3.fromRGB(170, 0, 0),
	["Intermediate"] = Color3.fromRGB(255, 85, 0),
	["Experienced"] = Color3.fromRGB(0, 85, 255),
	["Pro"] = Color3.fromRGB(0, 85, 0),
	["Awesome"] = Color3.fromRGB(255, 255, 0),
	["Amazing"] = Color3.fromRGB(0, 85, 255),
	["Expert"] = Color3.fromRGB(255, 170, 0)

local function update()
	for _, item in ipairs(displayFrame:GetChildren()) do
		if item:IsA("UIListLayout") then continue end
	for _, player in ipairs(players:GetPlayers()) do
		local leaderstats = player.leaderstats
		local rank = leaderstats.Rank
		local wins = leaderstats.Wins
		local elims = leaderstats.Knockouts
		local clonedFrame = statsFrame:Clone()
		local nameLabel = clonedFrame.PlayerName
		local playerStats = clonedFrame.Stats
		local elimsLabel = playerStats.Knockouts
		local rankLabel = playerStats.Rank
		local winsLabel = playerStats.Wins
		clonedFrame.Parent = displayFrame
		nameLabel.Text = "@"..player.Name
		rankLabel.Text = rank.Value
		rankLabel.TextColor3 = ranks[rank.Value]
		elimsLabel.Text = elims.Value
		winsLabel.Text = wins.Value
	return true

local function loadStats(player:Player)
	local leaderstats = player:WaitForChild("leaderstats")
	local rank = leaderstats:WaitForChild("Rank")
	local wins = leaderstats:WaitForChild("Wins")
	local elims = leaderstats:WaitForChild("Knockouts")
	local succeeded, failed = pcall(update)
	if not succeeded and failed then
	print("it managed to update :D")

sGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
1 Like

K so I am also a bit confused on this one tbh xD. Try removing “return true” and the pcall and just call the function one time normally.

1 Like

Sorry, I forgot to say I already tried that. I gave it another go and it still hasn’t worked - the pcall() was just there in case a player left mid-way through.

1 Like

I don’t remember what my work was exactly, but when I used ipairs() the script didn’t do for, do.
You can try changing it to pairs().
I don’t know if it will help because i doesn’t work with tables, but try it. ******** [Bad english]

1 Like

I just thought because GetPlayers() returned numerical keys, ipairs() might work. Changing it to pairs() didn’t work.


Ahh ok so I think I have an idea now. The update function perhabs isnt even firing in the laodStats function. It is only getting fired once at task.spawn. Make a print after the :WaitForChild yields and after the pcall to see to where it goes. Also, if this is a LocalScript, then playerAdded will only work on other Clients and not your Client itsself. And if this is a ServerScript, if you are certain that these leaderstats exist, then dont use WaitForChild on them in a ServerScript. If not, then using it one time at leaderstats should be enough

1 Like

yep hes only running loadstats for other people and not him, also OP change it so you change the stats (by saving the clonedFrame in a table or just changing its name) instead of deleting everything and cloning them again everytime a value changes

1 Like

I know that pairs() will iterate with any key, and ipairs() will only iterate with numerical keys. The problem was with PlayerAdded client-side, since it is a LocalScript, so I made it register server-side and fire a RemoteEvent every time someone joins, which would then call the update() function. I didn’t know that PlayerAdded wouldn’t work client-side, thank you so much for your time and help!


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