Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

In tables, why only 2 values are being printed?

local Left = script.Parent.Left

local LeftFront       = Left:FindFirstChild("UpFrontLeft")
local Left            = Left:FindFirstChild("Front")
local LeftRear        = Left:FindFirstChild("UpFrontBack")
local LeftFrontLower  = Left:FindFirstChild("DownFrontLeft")
local LeftLower       = Left:FindFirstChild("DownFront")
local LeftRearLower   = Left:FindFirstChild("DownFrontBack")

local L = {
	LeftFront,
	Left,
	LeftRear,
	LeftFrontLower,
	LeftLower,
	LeftRearLower
}

for index = 1, #F do
    local value = F[index]
    print(index, " = ", value)
end

It only prints:

  1  =  UpFrontLeft
  2  =  Front

If I change #F to 5, for example, it gives me:

  1  =  UpFrontLeft
  2  =  Front
  3  =  nil
  4  =  nil
  5  =  nil

3 comments

1

When it tries to FindFirstChild("UpFrontBack") for example it may not find anything. Change this to WaitForChild if you're executing this script the second the game loads.

1

I don't see any array titled F in this Script.

0

Sorry, I forgot to change the F part but it's the same thing, since I have another table called F

2 answers

You should use:

WaitForChild:
-- instead of
FindFirstChild:

This will allow things to load before your script just goes and rushes through everything. You could also put like a wait before the table so everything can load, but waitforchild is better.

2 comments

0

I tried doing so, but it just says "Infinite yield possible".

0

Then that means those parts don't exist yet.

So I found a very weird solution for this which could be found here, if you know why, please explain it to me!

This discussion is preserved as it was. New answers, comments, and votes are closed.