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

For Statement Help?

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?

1 comment

0

you are looping through a number, try doing table:GetChildren() instead of #table:GetChildren()

1 answer

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.

2 comments

0

But will my for statement work?

0

Test it.

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