How to make a loop without using loops (no recursion)

First create a new Actor using Instance.new() and make sure to parent it to the parent of the script

local actor = Instance.new("Actor", script.Parent)

Following, add a task.wait() in between, and something that you can use to tell if the loop is working. In this case, we’ll just use the good old print.

print("hello world")
task.wait()

Finally, the last step is to change the parent of the script to the actor.

script.Parent = actor

Your code should look like this:

local actor = Instance.new("Actor", script.Parent)
print("hello world")
task.wait()
script.Parent = actor

If you’ve done everything right, your output should behave like this:

image

This also works in live-games, I have tested it.

You should be able to see your memory increasing every 1~5 seconds by 1mb, sometimes 3-5mb.

1 Like

I have investigated this further, and the reason why it happens is because scripts placed under an actor are immediately executed, so changing its parent to the actor will make it run again and repeat the same process.

Why would you ever use this?
From what I can tell, you’re just unnecessarily creating Actor instances and never destroying them, loses so much memory.

1 Like

It’s obviously a joke to create awareness, because this is actually a flaw in the design of Actor and it should be addressed. I ran into this issue while scripting a system, now imagine if I had not noticed the loop…