How can you get for loops to go back to the very begin? Example :
Kids = model:GetChildren() for i=1,#Kids do print("Getting kids") if i==#Kids then print("Going back to the beginning") --Restart code end end
Kids = model:GetChildren() for i=1,#Kids do print("Getting kids") if i==#Kids then print("Going back to the beginning") --Restart code end end
Now, let me introduce you to something called a recursive. It's a pretty neat thing, and I'll give you the wiki definition.
Recursion is a form of looping, where a function calls itself, usually until a condition is met. Although recursion can be somewhat difficult to understand at first, it can result in much cleaner code.
So, let me explain how to do this in the form of your code. We have a function that runs the for loop. If the condition is meant for it to restart, then we will call the same function again.
function Kids() -- create the function Kids Kids = model:GetChildren() for i=1,#Kids do print("Getting kids") if i==#Kids then print("Going back to the beginning") return Kids() -- If the condition is met, do the function again. Otherwise, do not repeat. end end end Kids() -- start it up again.
Make it a function
Kids = model:GetChildren() function GetKids() Kids = model:GetChildren() for i=1,#Kids do print("Getting kids") if i==#Kids then print("Going back to the beginning") end end end
And also add another function for every time you 'get kids'
while true do wait(30) -- Lets say every 30 seconds you want to GetKids() GetKids() end