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

For Statement Help?

Asked by
Mowblow 117
10 years ago

If I were to try and create a for loop that checks for the children of the contents of of a table, how would I do it? MY current idea is:

local 1 = game.Workspace.Part1
local 2 = game.Workspace.Part2
local 3 = game.Workspace.Part3
local table = {1,2,3}

for _, v in pairs (#table:GetChildren())
 if v:FindFirstChild("Value1") == true then
v:Destroy()
end
end

Is this correct?

0
you are looping through a number, try doing table:GetChildren() instead of #table:GetChildren() greatneil80 2647 — 5y

1 answer

Log in to vote
-1
Answered by
hiccup111 231 Moderation Voter
10 years ago

Variables have to start with a letter:

local p1 = game.Workspace.Part1
local p2 = game.Workspace.Part2
local p3 = game.Workspace.Part3

You can stack the parts straight into a table:

local tab = {Workspace.Part1,Workspace.Part2,Workspace.Part3}

Also, any word that shows up highlighted (blue) in ROBLOX.Lua, cannot (or shouldn't be) used as variables. It'll either causes errors or problems for you in the future.

Another thing, the method ":GetChildren()" can only be used on Instances, and returns a list of objects.

Since you've already made a table, you do not need to use the GetChildren() method. This will cause errors.

0
But will my for statement work? Mowblow 117 — 10y
0
Test it. hiccup111 231 — 10y
Ad

Answer this question