Making a chat-like gui system using UI Layouts?

I have a script that adds TextLabels to a Frame that has a UI Layout. I want to make it so that when there is no more space for another textlabel to be seen, the top one will get destroyed/pushed up to make room for the textlabel, so essentially something like the roblox chat. Is it possible to do it with UI Layouts/Constraints, and what settings should I use?

image
(Before text label is added)
image
(After text label is added)

3 Likes

I don’t think that this is possible purely with UI layouts or constraints. This is actually mainly scripting, so I think the topic should go in #help-and-feedback:scripting-support, instead.

I don’t know the specifics of the chat system you have, but I’ll provide a basic outline:

local frame = script.Frame --container for all the "chat" lables

frame.ChildAdded:Connect(function(child)

    local age = Instance.new("IntValue", child)
    age.Name = "Age"
    child.Age.Value = 1 --age is an int value inside the child
   
    for i, v in pairs(frame:GetChildren()) do

        if v.Age.Value == 4 then --you only have four text labels, increase if you have more

            v:Destroy()
            break

        end

    end

end)

Hopefully, that helps!

1 Like