I was reading about a little bit and came across a Topic which talked about too many While True Do loops causing lag.
Would this actually make significant lag, and if so is there a more efficient replacement that I could use in the same manner?
local colour = {BrickColor.new("Really red"),
BrickColor.new("Institutional white"),
BrickColor.new("Bright yellow"),
BrickColor.new("Lime green"),
BrickColor.new("Electric blue")}
while true do
for i = 1,#(colour),1 do
for _, v in pairs(script.parent:GetChildren()) do
if v:IsA("BasePart") then
v.BrickColor = colour[i]
end
end
wait(0.4)
end
end
This is my script… Is While True Do the best option here, even if I were to hypothetically have 100 of these scripts in a game?
If the codes are just checking a part to make sure it reaches a requirement or it’s just changing number values around I doubt It can make you lag. If you are however duplicating and deleting parts around, it might (not sure). But to hypothetically have 100 of them in your game it can cause lag depending on what it does.
Normally shouldn’t cause lag, as I have 500+ while true do loops in my game regarding tweens in one of my games I’m working on. But if you would hypothetically made the loops do very complex things, then there is a chance more lag would occur, the best way to test it is by publishing it on a private place, running it without the scripts, click SHIFT+F5, check your fps, and do the same with the scripts.