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

[SOLVED]Why is it not doing in pairs but just part for part? No errors

i did this but i does part for part not at the same time?

while true do
	for i,v in pairs(script.Parent.Kant:GetChildren()) do
		print(v)
		v.Material = "Neon"
		v.BrickColor = BrickColor.new("Deep blue")
		v.PointLight.Enabled = true
		wait(0.2)
		v.Material = "Glass"
		v.BrickColor = BrickColor.new("Bright blue")
		v.PointLight.Enabled = false
	end
	wait(0.2)
	for i,v in pairs(script.Parent.Kant2:GetChildren()) do
		v.Material = "Neon"
		v.BrickColor = BrickColor.new("Deep blue")
		v.PointLight.Enabled = true
		wait(0.2)
		v.Material = "Glass"
		v.BrickColor = BrickColor.new("Bright blue")
		v.PointLight.Enabled = false
	end
end

1 answer

For In Pairs loop does not loop them all at the same time, it loops it through then goes to the next one. If you want them to all loop at once use the spawn() function.

while true do
    for i,v in pairs(script.Parent.Kant:GetChildren()) do
    	spawn(function()
	        print(v)
	        v.Material = "Neon"
	        v.BrickColor = BrickColor.new("Deep blue")
	        v.PointLight.Enabled = true
	        wait(0.2)
	        v.Material = "Glass"
	        v.BrickColor = BrickColor.new("Bright blue")
	        v.PointLight.Enabled = false
    	end)
    end
    wait(0.2)
    for i,v in pairs(script.Parent.Kant2:GetChildren()) do
    	spawn(function()
	        v.Material = "Neon"
	        v.BrickColor = BrickColor.new("Deep blue")
	        v.PointLight.Enabled = true
	        wait(0.2)
	        v.Material = "Glass"
	        v.BrickColor = BrickColor.new("Bright blue")
	        v.PointLight.Enabled = false
    	end)
    end
end

6 comments

0

i don't want it at once first kant then Kant2

0

Thats what it does but it does everything in Kant at the same time then after that everything in kant2 at the same time.

0

Nope is does evertything at the same time....

0

If you want it to wait till its finished you need to either add a longer wait or have it go as it was before.

0

not working

0

Did you add a longer wait?

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