this is my script
local script = script.Parent local folder = script:GetChildren() for _, v in pairs(folder) do if v:IsA("MeshPart") then print("hi") while true do wait(.2) v.Color = Color3.fromRGB(math.random(1,255),math.random(1,255),math.random(1,255)) end end end
So my script works perfectly fine, other than only 1 "hi" is printed and only 1 part does the color changing. The MeshPart that is changing colors is also not the first child in the Model.
It's because the while true do
stops the whole entire for loop
. It just focuses on what's inside the while loop
and not outside it
What I recommend you doing is making a seperate Script
for the changing color. Then put it to someone then name it to anything, AND BE SURE TO DISABLE IT. For now, let's name it "ColorChange"
-- Color Change Script: while true do wait(.2) script.Parent.Color = Color3.fromRGB(math.random(1,255),math.random(1,255),math.random(1,255)) end
Then in your main script
-- Main Script: local script = script.Parent local folder = script:GetChildren() local colorChangeScript = wherever.you.put.it.ColorChange for _, v in pairs(folder) do if v:IsA("MeshPart") then print("hi") local colorChangeScriptClone = colorChangeScript:Clone() colorChangeScriptClone.Parent = v colorChangeScriptClone.Disabled = false end end
If it helped, be sure to accept it as an answer :D