My overhead gui script does not work

  1. What do you want to achieve?
    Well, I want that everytime an player joins an billboardgui is attached to their head, and also updating the text on the billboard gui on the corresponding thing.

  2. What is the issue?
    Well when the player joins the overheadgui falls and doesnt stay on the character head and isnt updated like it should.
    image

  3. What solutions have you tried so far?
    I have rewritten the code 3 times, put the billboard gui on the startergui, asked chatgpt but nothing worked.

local NameGUI = game.StarterGui.Nome
local RankGUI = game.StarterGui.Patente
local TeamGUI = game.StarterGui.Time

game.Players.PlayerAdded:Connect(function(Player)
	task.wait(4)

	local leaderstats = Player:FindFirstChild("leaderstats")
	local Rank = leaderstats and leaderstats:FindFirstChild("Rank")

	Player.CharacterAdded:Connect(function(Character)
		local NewNameGUI = NameGUI:Clone()
		local NewRankGUI = RankGUI:Clone()
		local NewTeamGUI = TeamGUI:Clone()

		NewNameGUI.Name = Player.Name .. " Name"
		NewRankGUI.Name = Player.Name .. " Rank"
		NewTeamGUI.Name = Player.Name .. " Team"

		local Head = Character:WaitForChild("Head")

		NewNameGUI.Parent = Head
		NewNameGUI.Adornee = Head
		NewNameGUI.TextLabel.Text = Player.Name
		NewNameGUI.TextLabel.TextColor3 = Color3.new(1, 1, 1)

		NewRankGUI.Parent = Head
		NewRankGUI.Adornee = Head
		NewRankGUI.TextLabel.Text = Rank and Rank.Value or "[NA] No Rank"
		NewRankGUI.TextLabel.TextColor3 = Player.TeamColor.Color

		NewTeamGUI.Parent = Head
		NewTeamGUI.Adornee = Head
		if Player.Team then
			NewTeamGUI.TextLabel.Text = Player.Team.Name
			NewTeamGUI.TextLabel.TextColor3 = Player.TeamColor.Color
		else
			NewTeamGUI.TextLabel.Text = "No Team"
			NewTeamGUI.TextLabel.TextColor3 = Color3.new(1, 1, 1)
		end

		if Rank then
			Rank.Changed:Connect(function(newValue)
				NewRankGUI.TextLabel.Text = newValue
			end)
		end

		Character.Humanoid.Died:Connect(function()
			NewRankGUI.TextLabel.Text = Rank and Rank.Value or "[NA] No Rank"
		end)
	end)
end)

try removing the task.wait(4) at the start, i think its only getting players who spawned after 4 seconds

Your BillboardGui is parented to StarterGui, which means when a Player spawns it’ll be automatically cloned to their PlayerGui. This means that the Gui will still be visible to the player, just without an Adornee (so defaults to position: Vector3.new(0, 0, 0)).

I copied your script, moved the Gui to ReplicatedStorage, and it’s working fine for me. You could also just set the Enabled property off, then turn it back on once a Gui has been cloned for a new player.

image

My only other adjustments were to set Rank to:

local Rank = nil;--leaderstats and leaderstats:FindFirstChild("Rank")

As I don’t have a leaderstats in this game and couldn’t be bothered to add one.
image
The text still updated correctly (it is correct for all, it’s just the TextColor is the same as the BackgroundColor in my first screenshot).

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