How do I make a billboardgui scale like the player's name

The player’s name scales in a step-wise fashion where at certain distances it’ll shrink or grow and I have no clue how to recreate that (especially without clipping outside the billboard)
How should I go about doing it?

1 Like
  1. Create a BillboardGui for each player’s name above their character.
  2. Use a TextLabel within the BillboardGui to display the player’s name.
  3. Find the distance between the player’s character and the camera.
  4. Based on the distance, adjust the size of the TextLabel within the BillboardGui.
  5. Make sure the TextLabel does not clip outside the BillboardGui by setting its Clipping property to true.

If you set the size of the billboard to an offset instead of scale, then set the textbox to scales of 1, I believe it should work.

Welp this took an embarrassing amount of time, but if anyone wants it here’s the finished code

local RunService = game:GetService("RunService")
local baseName = "Draw Name "
local registered = {}
local function unregister(name)
	if typeof(name) == "Instance" then name = name.Name end
	RunService:UnbindFromRenderStep(baseName..name)
	if registered[name] then registered[name]:Destroy() end
end
function register(player:Player)
	if player == game.Players.LocalPlayer then return end
	local label = script.Username:Clone()
	label.Text.Text = player.Name
	label.Name = player.Name
	label.Text.TextColor = player.TeamColor
	repeat wait() until player.Character
	local char = player.Character
	local name = player.Name
	if registered[name] then unregister(name) end
	label.Parent = game.Players.LocalPlayer.PlayerGui
	label.Adornee = char:WaitForChild("Head")
	local debounce = false
	registered[name] = label
	RunService:BindToRenderStep(baseName..name, Enum.RenderPriority.Camera.Value - 1, function()
		local camera = workspace.CurrentCamera
		if not char or not char:FindFirstChild("Head") or not label or not label:FindFirstChild("Text") then
			warn("Sanity check failed", char, char:FindFirstChild("Head"), label, label:FindFirstChild("Text"))
			unregister(name)
			return
		end
		local distance = (camera.CFrame.Position-char.Head.Position).Magnitude
		local size = 23-(5*math.clamp(math.floor(distance/25), 0, 3))
		if distance > 90 then
			local transparency = math.clamp((distance-90)/10, 0, 1)
			label.Text.TextTransparency = transparency
		end
		label.Size = UDim2.new(label.Size.X.Scale, label.Size.X.Offset, 0, size)
	end)
end
function playerAdded(player)
	if player == game.Players.LocalPlayer then return end
	if player.Character then register(player) end
	player.CharacterAdded:Connect(function()
		register(player)
	end)
	player.CharacterRemoving:Connect(function()
		unregister(player)
	end)
	player:GetPropertyChangedSignal("TeamColor"):Connect(function()
		local label = registered[player.Name]
		if label and label:FindFirstChild("Text") then
			label.Text.TextColor = player.TeamColor
		end
	end)
end
repeat task.wait() until game:IsLoaded()
for i,player in pairs(game.Players:GetPlayers()) do
	playerAdded(player)
end
game.Players.LocalPlayer.CharacterAdded:Connect(function()
	for i,player in pairs(game.Players:GetPlayers()) do
		unregister(player)
		task.wait()
		register(player)
	end
end)
game.Players.PlayerAdded:Connect(playerAdded)

And a model with an included billboard: https://create.roblox.com/marketplace/asset/15274947357/Custom-username-with-scaling
This code is definitely not perfect and if you have any suggestions or find an issue please let me know

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