Do while true do loops break when the parent of the script is destroyed/nil?

Kinda basic question but

assume this is in a BillboardGUI in a player’s head

local clr = Color3.fromRGB
local Colors = {
	clr(255,0,0),
	clr(255,175,0),
	clr(255,255,0),
	clr(0,255,0),
	clr(0,0,255),
	clr(75,0,130),
	clr(143,0,255)
}

while true do
	for i = 1,#Colors do
		wait(1)
		script.Parent.TextColor3 = Colors[i]
	end
end

If the player left, would the loop still continue causing memory usage? (i need to know if it’s worth it to change the true to script.Parent)

Edit: Just to clarify, by break i mean end, not error

Hello.
Yep, you are right! The while loop will actually stop when you remove the parent of the script or script itself.

I hope I answered your question,
Have a great rest of your day!

1 Like

That’s interesting behavior I never knew that. Might as well start writing it as “while script do…”

Yep! It is kinda interesting. I thought it was like that so I made a quick test inside of Roblox Studio by placing a script into a folder that was while wait() do print("hey") end. Once I deleted the folder, the script stopped printing, so I’m pretty sure I’m right!

1 Like

Yup! Just tested it out myself. You can disable, enable, cut, and paste and it all works as expected. That’s pretty awesome.