This is just a matter of creating a function that measures whether the amount of frames and their sizes is too much for the frame to contain, or enough for the frame to contain. This being said, I will try to go over how you could possibly do this.
Assuming you want all the frames to be the same size until the container frame can not hold the amount of frames inside of it, you will need to evaluate how many spaces there will be based on the amount of frames there are in the container.
This will look something like this:
local frame_number = 1
local space_number = frame_number + 1
After you have the amount of spaces, you need to evaluate the x size of the frames. For simplicity, we will use the x scale size.
local frame_scale_x = 0.2
local total_frame_scale_x = frame_scale_x*frame_number
local remaining_space = 1-total_frame_scale_x
Once you have the remaining x scale left in the container, you need to calculate the amount of space needed in between the frames in order for them to be equally spaced. This is easy, since all you need to do is divide the remaining_space by space_number.
local spacing_size = remaining_space/space_number
Now you need to position the frames in their respective positions. This can be done with a function, like so:
function getPosX(frame_num)
local spacing = spacing_size*frame_num
local sizing = frame_scale_x*(frame_num-1)
return spacing+sizing
end
In order for this to work, you need to make sure that the spacing between each frame is greater than or equal to zero, otherwise the frames will be on top of eachother. If you want the frames to be on top of one another, just don't include the following condition:
if spacing_size >= 0 then
end
Once you have all this, you are ready to create your frames.
The full script should look something like this:
local container = script.Parent
local frame_scale_x = 0.2
local frame_number = 5
local space_number = frame_number+1
local total_frame_scale_x = frame_scale_x*frame_number
local remaining_space = 1-total_frame_scale_x
local spacing_size = remaining_space/space_number
function getPosX(frame_num)
local spacing = spacing_size*frame_num
local sizing = frame_scale_x*(frame_num-1)
return spacing+sizing
end
if spacing_size >= 0 then
for i=1,frame_number do
local f = Instance.new("TextLabel", container)
f.Size = UDim2.new(frame_scale_x, 0, 0.9, 0)
f.Position = UDim2.new(getPosX(i), 0, 0.05, 0)
f.Text = "#" .. tostring(i)
end
end
I hope this helped!
ALSO: If you want there to be more space for the frames, just make frame_scale_x smaller. :)