Problem offsetting a device icon in my username tag system

hey there, I’ve been working on a username system for a bit now, but I’m having problems offsetting the device icon with the username to keep a consistent look

this is the source code right now, I’m not sure how I can debug it
my current problems are

  1. converting offset to scale accurately
  2. offsetting the device icon with said scale
  3. finding why it’s erroring
local textService = game:GetService("TextService")

local playerTag = script.Parent
local deviceIcon = playerTag.Parent:WaitForChild("DeviceIcon")

local displayName = playerTag.Display:WaitForChild("TextLabel")
local userName = playerTag.Username:WaitForChild("TextLabel")

local iconSize = deviceIcon.AbsoluteSize

local function getTextBounds()
	-- I'm using size 26 with :GetTextSize() because it's the size that fits inside the textlabel
	
	local message = displayName.Text
	local size = displayName.AbsoluteSize
	local bounds = textService:GetTextSize(message, 26, Enum.Font.Montserrat, size)
	return bounds + Vector2.new(1, 1)
end

local function convertOffset(offset)
	print(offset)
	local viewportSize = workspace.Camera.ViewportSize
	return ({offset[1] / viewportSize.X, offset[2] / viewportSize.Y})
end

local offset1 = getTextBounds() + (iconSize / 2)
local offset2 = convertOffset(tostring(offset1))
print("Final offset: " .. tostring(offset2))
--deviceIcon.Position = UDim2.

this is what it errors, apparently I have nil and a number (line return ({offset[1] / viewportSize.X, offset[2] / viewportSize.Y})

Workspace.bart.Head.UsernameDisplay.PlayerTag.Script:21: attempt to perform arithmetic (div) on nil and number

if anyone has any solutions, please help! thanks :coefficients:

hey, so I’ve updated my code a bit, it’s still a bit wonky

local textService = game:GetService("TextService")

local playerTag = script.Parent
local deviceIcon = playerTag.Parent:WaitForChild("DeviceIcon")

local displayName, displayText = playerTag.Display, playerTag.Display:WaitForChild("TextLabel")
local userName, userText = playerTag.Username, playerTag.Username:WaitForChild("TextLabel")

local iconSize = deviceIcon.AbsoluteSize

local function getTextBounds()
    local message = displayText.Text
    local size = displayText.AbsoluteSize
    local bounds = textService:GetTextSize(message, 26, Enum.Font.Montserrat, size)
    return bounds + Vector2.new(1, 1)
end

local function convertOffset(offset, absSize)
    local scale = offset / absSize
    scale = scale * 100
    scale = math.floor(scale)
    scale = scale / 100
    return scale --round up to 2 decimals
end

local function offsetDeviceIcon()
    repeat task.wait() until displayName.AbsoluteSize.X ~= 0

    print("X not 0")
    print("double checking: ".. displayName.AbsoluteSize.X)
    
    local absX = displayName.AbsoluteSize.X
    local absY = displayName.AbsoluteSize.Y
    
    local offset1 = getTextBounds().X + (iconSize.X / 2)
    local offset2 = convertOffset(offset1, absX)
    local offset3 = 1 - offset2 --- 0.1
    
    print(offset3)
    return offset3
end

deviceIcon.Position = UDim2.new(offsetDeviceIcon(), 0, deviceIcon.Position.Y.Scale, 0)
--print("abs size: ".. absX)
--print(offset2)
--deviceIcon.Position = UDim2.

output:

nevermind, I offset it by half then halved the name offset