Nametag exactly above head

I am trying to get the nametag to always show above the head.

Here is my current algorithm, the issue is that I use characters and so the head is not always the same size, due to things such as hats etc. which produces a bad result of the nametag clipping or appearing too far up/low down.

Untitled Game - Roblox Studio (gyazo.com)

nametag.StudsOffsetWorldSpace = Vector3.new(0,head.Size.Y,0)```
1 Like

Use BillBoardUi.AlwaysOnTop, this will remove the light influence property though

1 Like

That just makes it clip over it. I want it to be set above the head.

1 Like

Maybe use the largest/highest accessory handle and offset it up by a few studs + the difference between the top of the handle and the top (or middle/bottom) of the head.

1 Like

I wrote this code that changes the offset depending on the accessories the character is currently wearing:

local offsetY = head.Size.Y/2
for _, v in pairs(Character:GetChildren()) do
	if v:IsA("Accessory") then --If it is an accessory
		if (v.AccessoryType == Enum.AccessoryType.Hat) or (v.AccessoryType == Enum.AccessoryType.Hair) then --If accessory is on the head
			local currentAccessoryOffset = head.Size.Y/2 + (v.Handle.Position.Y - (head.Position.Y + head.Size.Y/2) + v.Handle.Size.Y/2) --Some complicated math (To learn how I calculated it, go to: https://devforum.roblox.com/t/-/2523500/6)
			offsetY = math.max(offsetY, currentAccessoryOffset) --Sets OffsetY to the maximum offset
		end
	end
end

nametag.StudsOffsetWorldSpace = Vector3.new(0, offsetY, 0)

And I will explain how I calculated the currentAccessoryOffset in a little bit.

2 Likes

How did I calculate currentAccessoryOffset: