Do for loops "rules" carry on?

for i, v in script.Parent:GetDescendants() do
	if v:IsA("Folder") or v:IsA("Model") or v:IsA("SpecialMesh") or v:IsA("WeldConstraint") or v:IsA("TouchTransmitter") or v:IsA("Script") or v.Name == "Cloud" then continue end
	print(v.Name)
	for ii, CLOUD_MESH in script.Parent:GetChildren() do
		if CLOUD_MESH:IsA("Folder") or CLOUD_MESH:IsA("Model") or CLOUD_MESH:IsA("SpecialMesh") or CLOUD_MESH:IsA("WeldConstraint") or CLOUD_MESH:IsA("TouchTransmitter") or CLOUD_MESH:IsA("Script") or CLOUD_MESH.Name == "CloudPlatform" then continue end
		print(CLOUD_MESH.Name)
	end
end

I tried to make two separate variables (v and CLOUD_MESH) using two for loops. I tested this code and it only printed v. Does the if statement for the first for loop carry on to the second for loop?

1 Like

Yes it should, it will using continue in the 1st for loop will skip the 2nd loop and it will move on to the next itteration.

How do I fix this?? I need two separate variables and I don’t want the first one to carry onto the 2nd loop.

1 Like

What do you mean by “the first one [carries] onto the 2nd loop”?

1 Like

If the if statements from the 1st loop carry onto to the 2nd loop if statements

The if statements are evaluated each time that the code is reached, if that’s what you mean?

I don’t understand? I’m asking if the if statement from the first loop also apply to the second loop.

Why would it? The first if statement is outside of the second loop.

It’s for some reason not printing CLOUD_MESH and only prints v from the first loop. I don’t know why?

I suspect that the if statement on line 5 of your code sample is excluding all possible values in the second loop. If you remove the if statement, do things output?

Let me try that. (Roblox characters lol)

Bro. I’m so sorry. I just realized…

I put :GetChildren() instead of :GetDescendants() and it filtered out everything.

Wait hold on, I think I just found something weird when I ran finished my code wth?

What do you mean?



How did this error??

When using task.spawn, you put the function as the first argument then any parameters after it, so you should do something like this:

task.spawn(CLOUD_COLOR_TOGGLE, CLOUD_MESH)
task.spawn(STRIKE_PLAYER, hit.Parent:FindFirstChild("Humanoid"), hit.Parent:FindFirstChild("Head"), v)

Dang, I didn’t know that? I thought you put the parameters inside of the function.


Okay, something is a bit wrong? Whenever I step on a cloud it’s supposed to change that cloud’s color but instead it changes the certain cloud’s color (in the screenshot)

2 Likes

Both of the following are same:

for i = 1, 16 do
  if i % 2 == 0 then
    continue
  end
  for j = 1, 32 do
    print(i, j)
  end
end
for i = 1, 16 do
  if not (i % 2 == 0) then
    for j = 1, 32 do
      print(i, j)
    end
  end
end

This applies in just about every other language.

Excluding old Lua 5.1, where continue is not a keyword.

1 Like