Help with GetChildren()

Hey,

Not sure if im just being stupid or not.
I have a script that is supposed to get all children and list them, i did a print to see if it has them all and it shows all the numbers that are meant to be there, however it only shows 29 of them in the gui (they are labeled 1-37 to keep track of it in the list) however anything past 29 doesnt show up.

Not sure if im missing something or just been looking at it for so long??

heres the script:

for i,v in pairs(Frame:GetChildren()) do -- buy the rebirths
	if v:IsA("TextButton") then
		spawn(function()
			--print(v.Name)
			while true do
				wait()
				v.TextLabel.Text = Short.en(v.Rebirth.Value).. " Rebirths For " .. Short.en(Rebirths.Value * v.multprice.Value) .. " Clicks"
				if Coins.Value >= Rebirths.Value * v.multprice.Value then
					v.Button.BackgroundColor3 = Color3.new(0, 255, 0)
					v.Button.Frame.BackgroundColor3 = script.Parent.Green.Value
				else
					v.Button.BackgroundColor3 = Color3.new(255, 0, 0)
					v.Button.Frame.BackgroundColor3 = script.Parent.Red.Value
				end
			end
		end)
		v.Button.MouseButton1Click:Connect(function()
			--local pets = Player.Pets
			local mult = 1
			local testmulti = 1
			--for i,v in pairs(pets:GetChildren())do
			--	if v.Equipped.Value == true then
			--		mult = mult + v.Equipped.Parent.Multiplier2.Value
			--	end
			--end
			if Coins.Value >= Rebirths.Value * v.multprice.Value then
				game.Workspace.Events.AddRebirth:FireServer(v.Rebirth.Value)
				Player.leaderstats.Clicks.Value = 0
				if v.Rebirth.Value >= 100000000 then
					print(v.Rebirth.Value)
					RS:FireServer()
				end
			end
		end)
	end
end

Anyone notice why it doesnt show them all??

Thanks

1 Like

They all most likely didn’t load in yet when the script runs

Hello, how are you doing?

Try putting a wait(5) before the code. The issue is most likely that they didn’t load yet.

Why are you putting events in workspace? Events belong in ReplicatedStorage, so they are replicated to the client.

i put in a wait(5) didnt make any difference.

Were you printing inside of the if v:IsA("TextButton") then or outside of it? Are they all Textbuttons? Are some inside of others?

im printing inside of it to see if it lists all of the buttons (which is does)
yes all text buttons, no they are inside a scrollingframe, just numbered 1-37. then they have values in them for the number or rebirths it is.

But when i open the rebirth menu in the game only the first 29 are showing and the last 8 are not.

Is it because studio lists numbers in chronological order and so when they have an “absoluteposistion” that messes them up?

How are you sizing the text buttons? Scale or Offset? Maybe try to increase the canvasSize of the ScrollingFrame?

If the problem is what @HugeCoolboy2007 said, here is my recommendation:

  • Take the code out of your for loop and put it into a function, something like setUpChild(child)
  • Use a for loop, just like the one you have, and loop through all the children running the function on them
  • Connect to .ChildAdded and run the function on the children that are added.

Example:

local function setUpChild(child)
     -- set up child
end
for i,v in pairs(Frame:GetChildren()) do
     setUpChild(v)
end
Frame.ChildAdded:Connect(function(child)
     setUpChild(child)
end)

Sorted it now thanks for the help guys!

Can you mark this as solved so others know please?
Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.