Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

In tables, why only 2 values are being printed?

Asked by 5 years ago
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
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. EpicMetatableMoment 1444 — 5y
1
I don't see any array titled F in this Script. Ziffixture 6913 — 5y
0
Sorry, I forgot to change the F part but it's the same thing, since I have another table called F carlito1236 24 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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.

0
I tried doing so, but it just says "Infinite yield possible". carlito1236 24 — 5y
0
Then that means those parts don't exist yet. CaptainD_veloper 290 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question