##Why do I have a recursive function? In my script, I have this function that checks if there is a value called "Status".
NOTE: THERE IS CODE IN BETWEEN THE LOOPS AND IF STATEMENTS THAT I DIDN'T SHOW
local function recursive(model)
for _,child in pairs(model:GetChildren()) do
for _,descendant in pairs(child:GetChildren()) do
if descendant:IsA("StringValue") and descendant.Name:lower() =="status" then
if string.sub(descendant.Value,1,4):lower() == "jump" then
--code
elseif string.sub(descendant.Value,1,5):lower() == "speed" then
--code
elseif string.sub(descendant.Value,1,4):lower() == "kill" then
--code
end
else
recursive(descendant)
end
end
end
end
recursive(newMap) -- newMap is declared before in the actual script
##What is newMap?
newMap is a map that is being cloned into Workspace. I have declared this variable before so you don't have to worry about that.
##Status
Status is supposed be in a model, not added.
As you can see, I am using recursion. However, I want to avoid using recursion as much as possible for good performance in my game. Is there an alternative to recursion?

5 comments
This isn't recursive. The
recursivefunction never calls itself. Are you somehow cloning the script itself into its target to recurse?No, actually, you can call a function inside of itself.
Oh, I get it. I had insertScript(). I changed the name to recursive() because it would be more understandable. In the actual script, it would clone the scripts to parent of Status. Sorry about the confusion.
Rather than calling the function on descendant, maybe instead push descendant to a stack, and have a
whileloop running until the stack is empty? Each loop would pop an element from the stack, and run what recursive currently does on it.What do you mean by, "... push descendant to a stack ..." and why would using a while loop be faster than using recursion(Not as a negative thing. I just want to know if it is faster. I would like some evidence)?