Billboard gui leaderstats value not updating

Hey developers, I’m currently trying to make an overhead gui that should display the player’s username, and display the Ranks leaderstat in a textLabel in the overheadGui. The issue is that when the ranks leaderstat changes in game, it is not updating to the new changed leaderstat value. I have tried implementing a update system, but it’s just not working. This is my code:

local nametag = game.ServerStorage.NameTag
local nametags = Instance.new("Folder", workspace)
nametags.Name = "nametags"

Tags = {
	["Owner"] = {
		["IDs"] = {1}, -- player IDS here
		["Color"] = Color3.fromRGB(255, 128, 0)
	},
}

game.Players.PlayerAdded:Connect(function(player)
	local newtext = nametag:Clone()
	newtext.Name = player.UserId
	newtext.Parent = nametags
	local namtext = newtext.NameText
	local ownertext = newtext.OwnerText
	local ranktext = newtext.RankText

	namtext.Text = player.Name

	local playerFound = false

	for tag, t in pairs(Tags) do
		if table.find(t["IDs"], player.UserId) then
			ownertext.Text = tag
			ownertext.TextColor3 = t["Color"]
			playerFound = true
			break
		end
	end

	if not playerFound then
		ownertext.Visible = false -- Hide OwnerText if player not found in any tag
	end

	player.CharacterAppearanceLoaded:Connect(function(char)
		local head = char:WaitForChild("Head")
		newtext.Adornee = head
		local humanoid = char.Humanoid
		humanoid.DisplayDistanceType = "None"
	end)

	local function updateRank()
		local hiddenStats = player:FindFirstChild("HiddenStats")
		if hiddenStats then
			local rankValue = hiddenStats:FindFirstChild("Rank")
			if rankValue then
				ranktext.Text = "Rank: " .. rankValue.Value
			end
		end
	end
	updateRank()

	-- Continuously update RankText every second
	while true do
		wait(1)
		updateRank()
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local plrnametag = nametags:FindFirstChild(player.UserId)
	if plrnametag then
		plrnametag:Destroy()
	end
end)

I’ll send clips in-game of the issue if needed! :slight_smile:

2 Likes

A little bit different of an approach …
(not tested may need some love)

local nametag = game.ServerStorage.NameTag
local nametags = Instance.new("Folder", workspace)
nametags.Name = "nametags"

Tags = {
	["Owner"] = {
		["IDs"] = {1},
		["Color"] = Color3.fromRGB(255, 128, 0)
	},
}

game.Players.PlayerAdded:Connect(function(player)
	local newtext = nametag:Clone()
	newtext.Name = player.UserId
	newtext.Parent = nametags
	local namtext = newtext.NameText
	local ownertext = newtext.OwnerText
	local ranktext = newtext.RankText
	namtext.Text = player.Name

	local playerFound = false
	for tag, t in pairs(Tags) do
		if table.find(t["IDs"], player.UserId) then
			ownertext.Text = tag
			ownertext.TextColor3 = t["Color"]
			playerFound = true
			break
		end
	end

	if not playerFound then
		ownertext.Visible = false
	end

	player.CharacterAppearanceLoaded:Connect(function(char)
		local head = char:WaitForChild("Head")
		newtext.Adornee = head
		local humanoid = char.Humanoid
		humanoid.DisplayDistanceType = "None"
	end)

	local function updateRank()
		local hiddenStats = player:FindFirstChild("HiddenStats")
		if hiddenStats then
			local rankValue = hiddenStats:FindFirstChild("Rank")
			if rankValue then
				ranktext.Text = "Rank: " .. rankValue.Value
			end
		end
	end
	updateRank()

	game:GetService("RunService").Heartbeat:Connect(function()
		updateRank()
	end)

	player:WaitForChild("leaderstats").Changed:Connect(function()
		updateRank()
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local plrnametag = nametags:FindFirstChild(player.UserId)
	if plrnametag then
		plrnametag:Destroy()
	end
end)
2 Likes

I feel like this could be a solution, but I tried, and it doesnt work on my end sadly

nevermind, i figured the issue was in another script

1 Like

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