So right now, my frame only scales based on the text label for some reason.
Full Code:
local frame = script.Parent
local TextLabel = frame:WaitForChild("KillsLabel")
local ImageLabel = frame:WaitForChild("ImageLabel")
local BaseSize = TextLabel.Size.X
local RunService = game:GetService("RunService")
local TextService = game:GetService("TextService")
local function resizeFrameToChildren(frame)
local maxWidth = 0
for _, v in ipairs(frame:GetChildren()) do
if v:IsA("GuiObject") then
local childAbsoluteSize = v.AbsoluteSize
maxWidth = math.max(maxWidth, childAbsoluteSize.X)
end
end
frame.Size = UDim2.new(UDim.new(0, maxWidth), frame.Size.Y)
end
local function ScaleTextLabel(textlabel)
local textSize = TextService:GetTextSize(textlabel.Text, textlabel.TextSize, textlabel.Font, Vector2.new(math.huge, math.huge))
local textWidth = textSize.X
local newSize = UDim2.new(0, textWidth, textlabel.Size.Y.Scale, textlabel.Size.Y.Offset)
local newPosition = UDim2.new(1.75, -textWidth, textlabel.Position.Y.Scale, textlabel.Position.Y.Offset)
if textWidth > BaseSize.Offset then
textlabel.Size = newSize
textlabel.Position = newPosition
end
end
RunService.RenderStepped:Connect(function()
ImageLabel.Position = UDim2.new(0, 20, ImageLabel.Position.Y.Scale, ImageLabel.Position.Y.Offset)
resizeFrameToChildren(frame)
end)
TextLabel:GetPropertyChangedSignal("Text"):Connect(function()
ScaleTextLabel(TextLabel)
end)
ScaleTextLabel(TextLabel)