Log in to vote

Maintaining an equivalent distance UDim between differently Sized GUIObjects? [Solved]

Asked by
Ziffixture 6785 Moderation Voter Community Moderator
2 years ago
Edited 7 months ago

I’m writing a CustomChat and I’ve got far enough to properly adjust the YOffset length judging if the #Characters returned are greater than the AbsoluteSize.X of the ChatLabel to “drop a line”. Yet as much as I try I cannot seem to determine a proper technique to adjust the ChatLabels to work their way through the ChatFrame, with different Lengths. The default is 1,-10,0,-25, as a new ChatMessage is called it will usually just reduce the UDim by 18 pixels. I want to maintain this distance between each TextLabels, yet how would I push up for example default Label Sizes with a 3Line ChatMessage laying in the middle, each has to be differently adjusted to accommodate for the Large TextLabel, primarily I would believe upward more than lower ChatLabels. This is what I’ve got so far.


function CreateChatLabel(ChattedMessage)
    local ChatLabel ="TextLabel")
    ChatLabel.Parent = ChattedMessages
    ChatLabel.Text = ChattedMessage
    ChatLabel.Name = "ChatLabel"
    ChatLabel.TextSize = 14
    ChatLabel.ZIndex = 2
    ChatLabel.Font = "ArialBold"
    ChatLabel.TextXAlignment = "Left"
    ChatLabel.Size =,-10,0,-25)
    ChatLabel.Position =,5,1,18)
    ChatLabel.BackgroundTransparency = 1
    ChatLabel.BorderSizePixel = 0
    ChatLabel.TextColor3 = Color3.fromRGB(255,255,255)
    ChatLabel.TextStrokeTransparency = 0.8
    ChatLabel.TextStrokeColor3 = Color3.fromRGB(0,0,0)
    for _,ChatLabel in ipairs(ChattedMessages:GetChildren()) do
        local StringAbosoluteSize =, ChatLabel.AbsoluteSize.Y)
        local StringtoFrame= TestService:GetTextSize(ChattedMessage, 5, "ArialBold", StringAbosoluteSize)
        if (StringtoFrame > ChatLabel.AbsoluteSize.X) then --// Pseudo code for Conditional Statement
           ChatLabel.Size = ChatLabel.Size -,0,0,-(-25))
        if (#ChattedMessages:GetChildren() > 9) then

I don’t have access to the algorithm I used for the determined push, but it was messy, I will upload it to this question early tomorrow morning, but for now, does anyone have any helpful tips or jumpstarts to get the information I need?

For those who cannot tell, the ChatMessages go from Bottom to Top

have you tested it? line 6 "ChatLabel" wrongly spelled as "ChatLable" also missing parentheses at the end. also for line 4, 6, 7 you should consider that x - 2x can be simplified to -x GoldAngelInDisguise 297 — 2y
Wait, so are you trying to push existing messages with different height up when another message is chatted? Rheines 661 — 2y
Yes, since they’re different sizes, also x -2x turns the negative relation into positive Ziffixture 6785 — 2y
I've got access to the Script, this is the whole thing Ziffixture 6785 — 2y
View all comments (12 more)
For the positing of the ChatLabel of Course Ziffixture 6785 — 2y
Could anyone also help me find potential calculation flaws? Ziffixture 6785 — 2y
Maybe UIListLayout will help? It will fill the chat container with the specified padding between elements regardless of size, and you can set VerticalAlignment to Bottom so it will fill from the bottom up. And change SortOrder to Layout, so the newest chat will always be at the bottom. No coding needed? Rheines 661 — 2y
I rather the coding, but the UIList layout would help, how could I configure this and apply, how do I organize my code if so? Ziffixture 6785 — 2y
If I must loose coding in order to let this work, the that's fine Ziffixture 6785 — 2y
The way I see it is that you have a container Frame with TextLabels containing the player's chatted messages. If you put a UIListLayout into the container, it will automatically sort all TextLabels into a list inside that Frame. If you set the properties I mentioned before, you can do something like this: Rheines 661 — 2y
All you need to do maybe is just to delete older messages when they reach the height of the frame. Also, to get the size of the string, you can use TextService:GetTextSize to return the size of the string in pixels. Rheines 661 — 2y
Damn,so many new methods that didn't exist before, thank you so much!! Ziffixture 6785 — 2y
No problem. Rheines 661 — 2y
Aren't there like UIGridLayouts and UIListLayouts that do this kind of thing suspectshot108 559 — 11mo
Why are you editing all of the properties in the Script, and not just cloning the text from elsewhere? It just makes your code look messy. brokenVectors 525 — 11mo
What part of this question is a year old did you not get? Ziffixture 6785 — 11mo

Answer this question