I am trying to make a log that shows all of the recent kills in the game. It will go in the top-right corner and show the killer’s name on the left, an icon to represent the used method in the killing, and then the victim’s name on the right. I am, however, running into problems with appropriately sizing the names of the player and ultimately the entire frame. I want the frame to shrink down in size to match the lengths of the players’ names while still having the image representing the method between the killer’s name and the victim’s name. I have made countless attempts for hours to figure out how to get this to work, although I believe it is best done using UIListLayout as a helper. That being said though, it is still not working correctly and the sizing is never right. This is the code I have as of present to manage the size:
local Adjust = {}
local TextService = game:GetService("TextService")
function Adjust.resize(activity, killerName, victimName)
local killerLabel = activity.Killer
local victimLabel = activity.Victim
local image = activity.MethodImage
local SIZE_PER_CHAR = #killerLabel.Text / killerLabel.Size.X.Scale
local DEFAULT_SIZE = killerLabel.Size.X.Scale
killerLabel.Text = killerName
victimLabel.Text = victimName
-- figure out required length
local killerNeeds = #killerLabel.Text * SIZE_PER_CHAR
local victimNeeds = #victimLabel.Text * SIZE_PER_CHAR
local SIZE_DOWN = killerNeeds + victimNeeds / DEFAULT_SIZE
-- fixed layout budget (stable UI rule)
local IMAGE_SCALE = image.Size.X.Scale / SIZE_DOWN
local TEXT_BUDGET = 1 - IMAGE_SCALE
-- weights
local k = #killerName
local v = #victimName
local total = math.max(k + v, 1)
local kShare = k / total
local vShare = v / total
-- apply sizes
image.Size = UDim2.fromScale(IMAGE_SCALE, 1)
killerLabel.Size = UDim2.fromScale(TEXT_BUDGET * kShare, 1)
victimLabel.Size = UDim2.fromScale(TEXT_BUDGET * vShare, 1)
-- resize the frame to fit the text
local TOTAL_SCALE = killerLabel.Size.X.Scale * SIZE_DOWN
activity.Size = UDim2.fromScale(TOTAL_SCALE, activity.Size.Y.Scale)
end
return Adjust
Note that I am using TextScaled for both text labels and that there is no padding in the UIListLayout. This is what the UI element looks like when tested with killerName = “10_letters” and victimName = “5_let” as inputs:

Note that the size of the scope, MethodImage.Size.X.Scale = 0, which is why “5_let” appears partailly off screen.
That being said, how can I fix my formula such taht names appear in the right size and that the frame appropriately sizes down to match the need for space? In one of my previous attempts, I tried using GetTextBoundsAsync but I was unsure of it’s effectiveness with the TextScaled property being enabled so I made another attempt.
This is what the GUI elements should look like in the end, note the element in red is not perfectly sized, but is much closer to the actual goal:

