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.

EDIT:

function CreateChatLabel(ChattedMessage)
    local ChatLabel = Instance.new("TextLabel")
    ChatLabel.Parent = ChattedMessages
    ChatLabel.Text = ChattedMessage
    ChatLabel.Name = "ChatLabel"
    ChatLabel.TextSize = 14
    ChatLabel.ZIndex = 2
    ChatLabel.Font = "ArialBold"
    ChatLabel.TextXAlignment = "Left"
    ChatLabel.Size = UDim2.new(1,-10,0,-25)
    ChatLabel.Position = UDim2.new(0,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 = Vector2.new(ChatLabel.AbsoluteSize.X, 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 - UDim2.new(0,0,0,-(-25))
        end
        if (#ChattedMessages:GetChildren() > 9) then
           ChattedMessages:GetChildren()[1]:Remove()
        end
    end
end

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

16 comments

0

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

0

Wait, so are you trying to push existing messages with different height up when another message is chatted?

0

Yes, since they’re different sizes, also x -2x turns the negative relation into positive

0

I've got access to the Script, this is the whole thing

0

For the positing of the ChatLabel of Course

0

Could anyone also help me find potential calculation flaws?

0

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?

0

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?

0

If I must loose coding in order to let this work, the that's fine

0

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: https://gyazo.com/9db6a60895797e68f95edd2fe3d13a45

0

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.

0

Damn,so many new methods that didn't exist before, thank you so much!!

0

No problem.

0

Aren't there like UIGridLayouts and UIListLayouts that do this kind of thing

0

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.

0

What part of this question is a year old did you not get?