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

How do I make this piece of code loop twice using something simple?

I have this code:

local outter = game.Workspace.all.outter:GetChildren()
local second = game.Workspace.all.second:GetChildren()
local third = game.Workspace.all.third:GetChildren()
local last = game.Workspace.all.last:GetChildren()
local x = 0

while true do

	for i,v in pairs(outter) do
		spawn(function()
		v.BrickColor = BrickColor.new("Really red")
		v.Material = "Neon"
		wait(0.5)
		v.BrickColor = BrickColor.new("Really black")
		v.Material = "SmoothPlastic"
		end)
	end
	wait(0.5)
	for b,n in pairs(second) do
        spawn(function()
		n.BrickColor = BrickColor.new("Really red")
		n.Material = "Neon"
		wait(0.5)
		n.BrickColor = BrickColor.new("Really black")
		n.Material = "SmoothPlastic"
	    end)
	end
	wait(0.5)
	for h,j in pairs(third) do
        spawn(function()
		j.BrickColor = BrickColor.new("Really red")
		j.Material = "Neon"
		wait(0.5)
		j.BrickColor = BrickColor.new("Really black")
	    j.Material = "SmoothPlastic"
	    end)
	end
	wait(0.5)
	for o,p in pairs(last) do
		spawn(function()
		p.BrickColor = BrickColor.new("Really red")
		p.Material = "Neon"
		wait(0.5)
		p.BrickColor = BrickColor.new("Really black")
		p.Material = "SmoothPlastic"
	        end)
		end
	wait(0.5)
	
end

To make it repeat, I tried doing this

local x = 0

while true do
    repeat until x == 2
--code
x = x+1

I thought that if I did this, that once the whole code ran, it would add 1 to x. After it did thise twice so that x == 2, then the code would just stop. But it didn't work. Any ideas? All help is appreciated!

1 answer

✓ Accepted answer

Use a for loop:

for i = 1,2 do
--code
end

1 comment

0

This worked! I was able to combine the while true do with the for loop. Thanks!

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