Custom leaderboard help

i made a custom leaderboard and i added a ssytem to make the leaderboard to show my leaderstats but i dont know how to make it update everytime pls help thanks!
this is my script(local)

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
local plrs = game.Players
local serverMax = plrs.MaxPlayers
local list = script.Parent.Frame.ScrollingFrame
local function updateui()
	for i,v in pairs(script.Parent.Frame.ScrollingFrame:GetChildren()) do
		if v:IsA("TextLabel") then
			v:Destroy()
		end
	end
	for i,v in pairs(game.Players:GetPlayers()) do
		local label = script.Template:Clone()
		label.Text = v.Name
		label.Cash.Text = v.leaderstats.Cash.Value
		label.Kills.Text = v.leaderstats.Kills.Value
		label.Deaths.Text = v.leaderstats.Deaths.Value
		label.Parent = list
	end
end
game.Players.ChildAdded:Connect(function()
	updateui()
end)
game.Players.ChildRemoved:Connect(function()
	updateui()
end)
updateui()

here is the gui
image

1 Like

Just use RunService to update the UI instead of anything else, it would update it every frame.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
local plrs = game.Players
local serverMax = plrs.MaxPlayers
local list = script.Parent.Frame.ScrollingFrame

local RunService = game:GetService("RunService")

local function updateui()
	for i,v in pairs(script.Parent.Frame.ScrollingFrame:GetChildren()) do
		if v:IsA("TextLabel") then
			v:Destroy()
		end
	end
	for i,v in pairs(game.Players:GetPlayers()) do
		local label = script.Template:Clone()
		label.Text = v.Name
		label.Cash.Text = v.leaderstats.Cash.Value
		label.Kills.Text = v.leaderstats.Kills.Value
		label.Deaths.Text = v.leaderstats.Deaths.Value
		label.Parent = list
	end
end

RunService.Heartbeat:Connect(function()
	updateui()
end)
1 Like

i know i can do this but wouldnt it glitch out since its deleting all and redoing the gui again every frame kinda inneficient maybe?but actually its working :slight_smile:

I don’t think it would glitch out, but I’m not used to this kind of thing either. It works as far as I know.

anyways thx for help! appreciate it