For i, v in pairs not working as intended

Heya, so I have been trying to make something hat will switch between my decals, as there is multiple screens and I can’t get the loop to work. I have tried several times and I find that it only effects one of the screens insteaf of all of them.

	for i, v in pairs (script.Parent.Parent.Parent.TVs:GetChildren()) do

		v.Decal.Texture = "http://www.roblox.com/asset/?id=6673940512"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675542594"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675545413"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675547067"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675549006"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675550558"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675552211"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675554709"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675561471"
		wait(10)
		v.Decal.Texture = ""
	end

If you could help it would be much appreciated.

Use a coroutine to put each thing on its own thread

for i, v in pairs (script.Parent.Parent.Parent.TVs:GetChildren()) do
	coroutine.wrap(function()
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6673940512"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675542594"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675545413"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675547067"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675549006"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675550558"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675552211"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675554709"
		wait(10)
		v.Decal.Texture = "http://www.roblox.com/asset/?id=6675561471"
		wait(10)
		v.Decal.Texture = ""
	end)()
end
1 Like

Thank you, but just so I can get a better understanding of the code can you tell me what the coroutine does.

Coroutines essentially put code into its own thread so it has no conflict will happen in the script. It puts each of that code in their own thread so the waits don’t impact the main thread

This should help give a bit more understanding