BillboardGui Randomly Being Destroyed

I have a script that adds a BillboardGui to the player’s head that is not working about half the time. It attaches to the player’s head as it should but sometimes it will mysteriously get destroyed. I’m confused about how this is happening and how to fix it. Please help me figure out how to fix this, thanks.

Example of the bug.

My code:

	local Character = player.Character or player.CharacterAdded:Wait()
	print(Character) -- Always prints the correct character
	jumpsDataStore:OnUpdate(jumpsUpdate)
	local overhead = game.ReplicatedStorage:WaitForChild("OverheadUI"):Clone()
	overhead.Parent = Character.Head
	print(overhead.Parent) -- Always prints "Head" as it should
	overhead.TextLabel.Text = "Jumps: "..jumps.Value
	print(overhead.TextLabel.Text)
	task.wait(1)
	print(overhead.Parent) -- Prints as nil sometimes (somehow destroyed?)

I havent seen that happen before
maybe it’s something like the code parenting the billboardgui before the character is in workspace (but after it’s added to the player), then when setting up the appearance, the billboard gets removed?

try checking if the character’s parent is in workspace first, or putting the billboardgui in PlayerGui and setting the adornee to the head

1 Like

Is it a local script? you haven’t precised that. From the picture, it looks like the gui only replicates on you.

Also, you haven’t shared the whole code, so how is player defined?

i think its local script
if script not localscript there big problem

It’s a server script. The player was defined from game.Players.PlayerAdded:Connect(function(player)

Your script looks fine, so there’s another script messing with it. Check and see if there’s something that unexpectedly destroys it.

I didn’t even think of this, thank you so much! I was confused about this for so long and it ended up being just 1 simple line fix. game.Workspace:WaitForChild(Character.Name)

Edit: Using adornee also works and I did that instead

1 Like
local nametag = game.ReplicatedStorage.NameTag

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local head = char:FindFirstChild("Head")
		repeat task.wait() until head ~= nil
		
		local newNametag = nametag:Clone()
		newNametag.Parent = head
	end)
end)