Group overhead rank errors

Hi, I’m making a cafe game and I would like some help with the custom group ranks/nametags. The nametags will display the group rank below their name, which will be bold.

I can’t get it to disappear behind parts like this:
https://gyazo.com/59fa17f05bf5bd6260841460504f039d

or disappear when zoomed out far:
https://gyazo.com/7d342542ca82bf7b03fe56388eedf7a2

GIFs were taken at Frappe V4. You can see for yourself if I was not detailed enough. :smiley:

Any support would really be appreciated. Please leave a response if you know how I can fix this.

My cafe: Pronto V1 - Roblox

What I have so far:

local commands = {}

function Create(ClassName)
 return function(Properties)
  local Obj = Instance.new(ClassName)
  for i,v in pairs(Properties) do
   if type(i) == 'number' then
    v.Parent = Obj
   else
    Obj[i] = v
   end
  end
  return Obj
 end
end
function HandleCharacter(Player, Character)
 local Custom = Character:WaitForChild('Head'):clone()
 Custom.Name = 'TastiesOverhead'
 Custom.Parent = Character
 Custom.face:Destroy()
 Character.Head.Transparency = 1
 Create'Weld'{
  Name = 'CustomWeld';
  Parent = Custom;
  Part0 = Character.Head;
  Part1 = Custom;
 }
 Create'BillboardGui'{
  Name = 'Nametag';
  Parent = Custom;
  Size = UDim2.new(5, 0, 0.5, 0);
  StudsOffset = Vector3.new(0, 2, 0);
  Create'TextLabel'{
   Name = 'NameLabel';
   BackgroundTransparency = 1;
   Size = UDim2.new(1, 0, 1, 0);
   Position = UDim2.new(0, 0, -0.8, 0);
   Font = 'ArialBold';
   Text = Character.Name;
   TextColor3 = Color3.new(1, 1, 1);
   TextScaled = true;
   TextStrokeTransparency = 1;
  };
  Create'TextLabel'{
   Name = 'RankLabel';
   BackgroundTransparency = 1;
   Size = UDim2.new(1, 0, 0.92, 0);
   Position = UDim2.new(0, 0, 0.2, 0);
   TextTransparency = .1;
   Font = 'SourceSansItalic';
   FontSize = Enum.FontSize.Size14;
   Text = Player:GetRoleInGroup(4915753);
   TextColor3 = Color3.new(1, 1, 1);
   TextScaled = true;
   TextStrokeTransparency = 1;
  };
 }

 Custom.BrickColor = Character.Head.BrickColor
 Character.Head.Changed:connect(function()
  Character.Head.Transparency = 1
  Custom.BrickColor = Character.Head.BrickColor
 end)
 Character.Head.Mesh.Changed:connect(function()
  Custom:WaitForChild('Mesh').MeshId = Character.Head:WaitForChild('Mesh').MeshId
 end)
end

local rainbow = function(callback)
local frequency = 0.1
local i = 0 
while true do wait()
local red = math.sin(frequency*i + 0)*127+128 
local green = math.sin(frequency*i + 2*math.pi/3)*127+128 
local blue = math.sin(frequency*i + 4*math.pi/3)*127+128 
callback(Color3.new(red/255,green/255,blue/255)) i = i+1 
end end 
function HandlePlayer(Player)
 if Player.Character then
  HandleCharacter(Player, Player.Character)
 end
 Player.CharacterAdded:connect(function(Character) HandleCharacter(Player, Character) end)
 if Player.UserId == 0 or Player.UserId == 0 or Player.UserId == 0 or Player.UserId == 0 then
  Player.CharacterAdded:connect(function(char) local label = char:WaitForChild("TastiesOverhead") 
   coroutine.resume(coroutine.create(rainbow),function(color)label.Nametag.RankLabel.TextColor3 = Color3.new(color.r,color.g,color.b)end) 
  end)
 end
end
game.Players.PlayerAdded:connect(function(b)
 HandlePlayer(b)
end)
for i,v in pairs(game.Players:GetPlayers()) do
  HandlePlayer(v) 
end 

Thanks!

For the future, it’s a good idea to search around the Developer Hub, as it may have answers to your questions. As such the answers could have been found on the BillboardGui page. But, here are the solutions:

  1. For the first problem, simply turn AlwaysOnTop to false.
  2. For the second one, change the MaxDistance to however many studs you wish.

And the two refrences:

Hope that helps!

Where would I put the AlwaysOnTop in the script?
Same with MaxDistance.

Thanks!

Create'BillboardGui'{
  Name = 'Nametag';
   
  AlwaysOnTop = false
  MaxDistance = --stud distance here
   
  Parent = Custom;
  Size = UDim2.new(5, 0, 0.5, 0);
  StudsOffset = Vector3.new(0, 2, 0);
  Create'TextLabel'{
   Name = 'NameLabel';
   BackgroundTransparency = 1;
   Size = UDim2.new(1, 0, 1, 0);
   Position = UDim2.new(0, 0, -0.8, 0);
   Font = 'ArialBold';
   Text = Character.Name;
   TextColor3 = Color3.new(1, 1, 1);
   TextScaled = true;
   TextStrokeTransparency = 1;
  };

This code is a bit messy, but I’d assume thats where it would go.

Sadly, that also did not work. I tried with the spaces:

 Name = 'Nametag';
   
  AlwaysOnTop = false
  MaxDistance = --stud distance here
   
  Parent = Custom;

and without

 Name = 'Nametag';
  AlwaysOnTop = false
  MaxDistance = --stud distance here
  Parent = Custom;

Instead of making everything in a script you can make a billboardgui and clone it. This way you don’t have to set all the properties.

still needing help with this btw

I suggest making a Billboard GUI then store it then clone it in the script instead of creating a new one with a script.

Module Script

local OverheadNames = {}


local CurrentOverheadNames = {}
function OverheadNames.Initialize()
	spawn(function()
		while true do
			wait()
			for i,v in pairs(CurrentOverheadNames) do
				--(player,Title,{BorderSize,BorderColor,BackgroundTransparency,BackgroundColor,TextColor,TextFont},{MaxDistance,AlwaysOnTop})
				local Player = v[1]
				local Name = v[2]
				local BorderSize = v[3][1] 
				local BorderColor = v[3][2]
				local BackgroundTransparency = v[3][3]
				local BackgroundColor = v[3][4]
				local TextColor = v[3][5]
				local TextFont = v[3][6]
				local MaxDistance = v[4][1]
				local AlwaysOnTop = v[4][2]
				if Player ~= nil then
					local PlayerCharacter = Player.Character or Player.CharacterAdded:Wait()
					if PlayerCharacter then
						if PlayerCharacter.Head:FindFirstChild("Overhead Rank") ~= nil then
							PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].Text = Name
							PlayerCharacter.Head["Overhead Rank"].MaxDistance = MaxDistance
							PlayerCharacter.Head["Overhead Rank"].AlwaysOnTop = AlwaysOnTop
							PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].Font = TextFont
							PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].BackgroundTransparency = BackgroundTransparency
							if type(BorderColor) == "string" then
								if BorderColor:lower() == "rainbow" then
									PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].BorderColor3 = Color3.fromRGB(math.random(1,255), math.random(1,255), math.random(1,255))
								end
							else
								PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].BorderColor3 = BorderColor
							end
							if type(TextColor) == "string" then
								if TextColor:lower() == "rainbow" then
									PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].TextColor3 = Color3.fromRGB(math.random(1,255), math.random(1,255), math.random(1,255))
								end
							else
								PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].TextColor3 = TextColor
							end
							if type(BackgroundColor) == "string" then
								if BackgroundColor:lower() == "rainbow" then
									PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].BackgroundColor3 = Color3.fromRGB(math.random(1,255), math.random(1,255), math.random(1,255))
								end
							else
								PlayerCharacter.Head["Overhead Rank"]["Overhead Rank"].BackgroundColor3 = BackgroundColor
							end
						else
							local OverheadGui = Instance.new("BillboardGui", PlayerCharacter.Head)
								OverheadGui.Name = "Overhead Rank"
								OverheadGui.Adornee = OverheadGui.Parent
								OverheadGui.AlwaysOnTop = AlwaysOnTop
								OverheadGui.MaxDistance = MaxDistance
								OverheadGui.StudsOffsetWorldSpace = Vector3.new(0,1.5,0)
								OverheadGui.Size = UDim2.fromScale(1.5,0.4)
							local TextLabel = Instance.new("TextLabel", OverheadGui)
								TextLabel.Name = "Overhead Rank"
								TextLabel.Size = UDim2.fromScale(1,1)
								TextLabel.Text = Name
								TextLabel.TextScaled = true
								TextLabel.BackgroundTransparency = BackgroundTransparency
								TextLabel.BorderSizePixel = BorderSize
								if type(BorderColor) == "string" then
									if BorderColor:lower() == "rainbow" then
										TextLabel.BorderColor3 = Color3.fromRGB(math.random(1,255), math.random(1,255), math.random(1,255))
									end
								else
									TextLabel.BorderColor3 = BorderColor
								end
								if type(TextColor) == "string" then
									if TextColor:lower() == "rainbow" then
										TextLabel.TextColor3 = Color3.fromRGB(math.random(1,255), math.random(1,255), math.random(1,255))
									end
								else
									TextLabel.TextColor3 = TextColor
								end
								if type(BackgroundColor) == "string" then
									if BackgroundColor:lower() == "rainbow" then
										TextLabel.BackgroundColor3 = Color3.fromRGB(math.random(1,255), math.random(1,255), math.random(1,255))
									end
								else
									TextLabel.BackgroundColor3 = BackgroundColor
								end
						end
					end
				else
					table.remove(CurrentOverheadNames,i)
					continue
				end
			end
		end
	end)
	print("Kylerzong's OverheadNames Module Ready")
end


function OverheadNames.UpdateName(Player, Name, DecorationTable, VisibilityTable)
	local Buffer = {
		Player,
		Name,
		DecorationTable,
		VisibilityTable
	}
	for i,v in pairs(CurrentOverheadNames) do
		if v[1] == Player then
			CurrentOverheadNames[i] = Buffer
			return true
		end
	end
	table.insert(CurrentOverheadNames, Buffer)
end


return OverheadNames

Regular Script

local OverheadNames = require(script.Parent)
--(player,Title,{BorderSize,BorderColor,BackgroundTransparency,BackgroundColor,TextColor,TextFont},{MaxDistance,AlwaysOnTop})

OverheadNames.Initialize()

Plyr = game.Players:WaitForChild("kylerzong",math.huge)

OverheadNames.UpdateName(Plyr,"Owner",{3,"rainbow",0,"rainbow","rainbow","Arial"},{math.huge, false})

wait(3)

OverheadNames.UpdateName(Plyr,"Slave",{0,Color3.fromRGB(255,0,0),0,"rainbow","rainbow","Arial"},{math.huge, false})

Non-Rainbow Example

local OverheadNames = require(script.Parent)

--(player,Title,{BorderSize,BorderColor,BackgroundTransparency,BackgroundColor,TextColor,TextFont},{MaxDistance,AlwaysOnTop})

OverheadNames.Initialize()

Plyr = game.Players:WaitForChild("kylerzong", math.huge)

OverheadNames.UpdateName(Plyr,"Owner",{2,Color3.fromRGB(255,0,0),0,Color3.fromRGB(0,0,0),Color3.fromRGB(255,0,0),"Arial"},{60, false})

Note: I have only done minimal testing, all of which I was solo, I haven’t tested it with multiple players.