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.
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.
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.