Problem with ScrollingFrame (Do not consider all children)

hello devlopers, I’m having a problem with the scrollingframe because it is not “Rendering” the frames (children)

Here is the script used to organize the ScrollingFrame:

 local FrameLobbyName  = "Lobby"
 local Bases =  workspace:WaitForChild("Bases")
 local ScrollingFrame = script.Parent.Frame.Frame.ScrollingFrame

for p = 1,#Bases:GetChildren() do
	local Clone = script.Sample:Clone()
	Clone.Name = "Stage"..p
	Clone.Stage.Text = "Stage"..p
	Clone.ButtonFrame.Button.Number.Value = p
	Clone.Parent  = script.Parent.Frame.Frame.ScrollingFrame
	 ScrollingFrame.CanvasSize = UDim2.new(0,0,0,ScrollingFrame.UIListLayout.AbsoluteContentSize.Y)
end

(NOTE: the “Bases” Model has 12 children!)

Here is the scrollingframe before the script (Initial):

Screenshot_30

Here is the scrollingframe After the script:

Screenshot_29

Here is how the scrolling frame looks in the game:

(I don’t know why, but when the scrollingframe is being executed by the script it does not consider the 12 frames, it only considers 9, if someone can help me I will be very happy!)

Something silly about UIListLayout.AbsoluteContentSize is that it does not update immediately right after adding GUI objects to its parent. You need to wait a frame before it decides to update.

Try doing this:

wait()
ScrollingFrame.CanvasSize = UDim2.new(0,0,0,ScrollingFrame.UIListLayout.AbsoluteContentSize.Y)
1 Like

The problem is that you’re updating the CanvasSize inside the for loop. Don’t. Move the updating of CanvasSize outside of the for loop. It is also worth noting that this takes out how much re-rendering the Gui engine does because it will only update CanvasSize after all the elements are filled rather than as it is adding.

By the way, if you don’t need scale and are only working with offset, you can use the fromOffset constructor. You only need to pass two values, the offsets for X and Y. Scale will be automatically filled with 0s (format {0, x}, {0, y}).

for i = 1, #Bases:GetChildren() do
    -- Perform
end
ScrollingFrame.CanvasSize = UDim2.fromOffset(0, ScrollingFrame.UIListLayout.AbsoluteContentSize.Y)

@Razorter Adding a wait to attempt to solve timing problems is a code smell. You should never try fixing problems with wait without significant reason. This does not include the wait method of RBXScriptConnections which still retains an event-based environment.

1 Like

This topic should help you:

Use GetPropertyChangedSignal before (outside of) your loop. This will allow you to adjust the size whenever the AbsoluteContentSize changes; e.g.

ScrollingFrame.UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
    ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, ScrollingFrame.UIListLayout.AbsoluteContentSize.Y)
end)

I would recommend assigning the UIListLayout to its own variable if you’re going to reference it multiple times though.

none of the above suggestions worked, the same problem remains ;-;

Have you checked to ensure all 12 children of the bases model have loaded before your script executes? It might be that they’re not physically there when the script is run so the script has only picked up 9 of them.

Try putting this before your loop, and see if it prints 12 to the output:
print(#Bases:GetChildren())

already tried it, it printed the 12 frames correctly, but the ScrollingFrame is still wrong

can this be caused by being a normal script and not a LocalScript?

I’d recommend using a LocalScript on the client for GUIs, definitely. You can use Elttob’s Reclass plugin to change it quickly.

I need a normal script to access player data storage

I think I discovered the error, I was using the Children as a scale but it has to be with OffSet

thanks for helping! :smile:

That’d work! haha.
But in reference to your previous message, you should really be handing player data on the server, and communicating with it via RemoteFunctions and RemoteEvents. This should not be accessible on the client.