For i,v in pairs runs very slow (and it shouldn't)

So I have a script that should play some animations onn a boolvalue.changed event, and in that script im using this kind of line of code:

for i,v in pairs() do

end

But with the following

Script
local value = script.Parent.Activated
local activate = workspace.Tower2.Lyoko:LoadAnimation(script.Activate)
local idle = workspace.Tower2.Lyoko:LoadAnimation(script.Idle)
local deactivate = workspace.Tower2.Lyoko:LoadAnimation(script.DeActivate)

value.Changed:Connect(function()
	if value.Value == true then
		activate:Play()
		
		for i, v in pairs(script.Parent:GetChildren()) do
			if v.Name == "Neon" then
				v.BrickColor = BrickColor.new("Really red")
			end
		wait(1.5)
		idle:Play()
		end
	else
		for i, v in pairs(script.Parent:GetChildren()) do
			if v.Name == "Neon" then
				v.BrickColor = BrickColor.new("Institutional white")
			end
		wait(1)
		deactivate:Play()
		end
	end
end)

the neon coloring runs very slow.
Here is a video of what i mean:


and it goes on until every neon part is red.
any help?

You have a wait(1.5) and a wait(1) in your loops, did you mean to put those outside of it?

1 Like

Yes, i want that, but studio wants them into the for i,v in pairs lines, idk why

Can’t you replace the loops with this

for i, v in pairs(script.Parent:GetChildren()) do
	if v.Name == "Neon" then
		v.BrickColor = BrickColor.new("Really red")
	end
end
wait(1.5)
idle:Play()

And this?

for i, v in pairs(script.Parent:GetChildren()) do
	if v.Name == "Neon" then
		v.BrickColor = BrickColor.new("Institutional white")
	end
end
wait(1)
deactivate:Play()
2 Likes

Thanks, it worked! There are a bunch of events there and i got confused :sweat_smile:

It’s okay, least you got your answer in the end! If you have anymore issues don’t be afraid to make another post!

1 Like