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
- converting offset to scale accurately
- offsetting the device icon with said scale
- 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