In a battle system I'm working on, each battle has a folder with the amount of players fighting and the players fighting, and the amount of enemies and the enemy object values. In a name generator function, the funciton generates a name for the folder to be called. To make sure each of these folder names are different to seperate them, it checks if the number it randomly chose is the same as to any of the folder names. However, the way I'm doing it doesn't work. What am I doing wrong?
function BattleScript.NameGenerator()
local number = math.random(100)
local stringnumber = tostring(number)
print(stringnumber)
for battles in game.ServerStorage.Battles do
if battles.Name == stringnumber then
BattleScript.NameGenerator()
else
return stringnumber
end
end
end
Thanks!

1 comment
Yes, this is called recursion. The function will call itself. Which can cause some sort of infinite loop if not done properly. Though such a loop usually ends up in a crash as jumping into a function uses up stack memory for the return address and local variables.