How can I create a certain amount of items based on the max number

Hello I am trying to figure out the math to making my code work below. What I want to do is insert a frame into the starterGui based on the number of children that are located in the “Holder” model. However I have a max number of frames that I want to be inserted into the starterGui and a max number of children that can be inserted into the holder.

--Workspace:
------Holder
--StarterGui:
--------LocalScript

local currFrames, maxFrames = 0, 3;
local currChildren, maxChildren = 0, math.random(4,7);

For example:

Let’s say the Holder model in the Workspace has 5 children and the maxChildren variable is also 5. If this were the case, then the total number of frames that should be inserted into the playerGui would be 3. Or, lets say there were only 3 children in the Holder model… Then only 2 frames would be inserted into the starterGui and so on.

I am trying to make this work evenly with any numbers that I choose.

game.Workspace.Holder.DescendantAdded:Connect(function(item)
  if #game.Workspace.Holder:GetChildren() > 0 then
    --Do math to figure out how many frames should be inserted into the starterGui.
  end
end)
local num = 3

for i = 1, num + 4, 1 do
	local part = Instance.new("Part")
	part.Parent = workspace
end

It seems you’re just adding “4” so just add 4 where necessary to achieve this. Like in the above script.

Do you mean to place the same amount of frames as the amount of childrens but still have a maximum amount of frames that can be placed? If so, you should use math.min() and a loop.
(You can also use math.clamp but this requires a minimum as well as a maximum)

--a small example
if numChildren > 0 then
 for i = 1,math.min(numChildren,maxFrames) do
  --create the frames
 end
end

If this is not what you are looking for or if I misunderstood the question, please tell me

Let’s see if i understand, do you pretend to make something like this?

If i’m holding 1 Item, i can get +4 of Something (Can be Anything)
If i’m holding 2 Item, i can get +3 of Something
if i’m holding 3 Item, i can get +2 of Something
if i’m holding 4 Item, i can get +1 of Something
if i’m holding 5 Item, i can get +0 of Something

or Something related to it? Your question is really confuse

or maybe is Option 2:
if i’m holding 1 Item, i can get +1 Coin
if I’m holding 2 item, i can get +2 Coins
if i’m holding 3 item, i can get +3 Coins
if i’m holding 4 item, i can get +4 Coins
if i’m holding 5 item, i can get +5 Coins
(Depending on the number of what i’m Holding , i get a bonus to get more Coins for example)

Just examples, do you pretend to do something like that?

No I just I want to insert a max of 3 Frames based on if the current children is at it’s max or not. So if:

CurrentChildren == 5 and MaxChildren == 5 then
currentFrames = 3 (maxFrames)

CurrentChildren == 3 and MaxChidren == 5 then
CurrentFrames = 2

CurrentChildren == 1 and MaxChildren == 5 then
CurrentFrames = 1

but I want to be able to do this with any number relating to MaxFrames, MaxChildren.

So what you mean is you want a percentage based on the amount of childrens and the maxAmount.

So, something like

num = math.floor((numChildren/maxChildren)*maxFrames+0.5)

?