How to make custom chat automatically delete a message after a certain amount of messages have been shown

Im making a custom chat, and one thing i cant figure out how to make older messages delete automatically after 50 messages are sent

For example the default roblox chat deletes messages that cant fit in the latest 50 messages.
image

Where it says “Chat ‘/?’ or ‘/help’ for a list of chat commands.”, in 50 messages and that message is at the top of the scrolling frame, it would be removed.

I dont know a better way on explaining my issue.

In your custom chat, there’s an area where your creating these msgs? correct me if i’m wrong.

If you mean a textbox then yes
heres how it looks in case if that helps

Then you can automatically remove them after a certain period of time with the Debris service

Example:

local DebrisService = game:GetService("Debris") 

local AutomatedRemoveTime = 40
local MsgBox = --whatever 

DebrisService:AddItem(MsgBox,AutomatedRemoveTime) -- Will not yield the script and will automatically remove the msg after the period of time has elapsed

I didnt mean after a period of time i meant after a certain amount of messages are sent

In that case you can create a IntValue that updates after a msg is added, It will hold the total amount of msgs that was sent, then from there you can add a listener for the IntValue that will check if the amount of msgs that you would want has been reached.