Attempted to index nil with :GetChildren()

I’m making a shop Gui. The player selects a collection and a scrolling frame pops up with all the items in the collection folder. I’m getting an error (below). There are items in the folder, why is it saying nil when there are items in the folder?

Collection Folder:
dsfds

Output:

Script:

local ScrollingFrame = script.Parent.Parent.Parent.CollectionPanel.ScrollingFrame
local Table = {}

for i, OptionButton in pairs(ScrollingFrame:GetChildren()) do
	if OptionButton:IsA("TextButton") then
		OptionButton.MouseButton1Click:Connect(function()
			local Folder = OptionButton.CollectionFolder.Value

			for i, Item in pairs(Folder:GetChildren()) do
				table.insert(Table, Item)
			end

			for i, TableItem in pairs(Table) do
				local CloneFrame = script.Parent.ScrollingFrame.OptionFrame:Clone()
				CloneFrame.Parent = script.Parent.ScrollingFrame
			end
		end)
	end
end

Thanks,

  • Skylexion

What is this line for?, it also may be because it thinks its a string/number.

It’s an object value. Each folder has its own collection folder value, so I can add a collection easier.

Could you show the explorer for the OptionButtons and their CollectionFolder ObjectValues?

1 Like

Ignore the mobile device thing, accidentally dragged it in there.

sad

Could you also show the properties of Collection6.CollectionFolder?

It’s an object value with the value of the Ragnerock folder.

Since it is saying attempt to index nul with ‘GetChildren’, this means that the Folder variable is nil. And with no other errors in relation to it, this means that CollectionFolder exists within each button as well. Therefore, one or multiple of the ObjectValues does not actually have a value, in turn returning nil.

Edit: Make sure that the folders you are referencing are in a location that the client can access. For example, do not put them in ServerStorage.

I want unowned items to be put in server storage so it doesn’t take up client memory.

If it is located in ServerStorage, then the client can not access the folders, resulting in the values of some of the ObjectValues to become nil. If you want them to work correctly, I recommend ReplicatedStorage. The client has no access whatsoever to ServerStorage.

1 Like

Can I replace the localscript with a server script ?

User interface scripts should always be local.

1 Like