Whats up! so, im a pretty advanced scripter and im making a tower defense game, but im running into a problem that is, the system that i use for making the enemy move to the next nodes is for i = 1, #nextnodes do, and i was wondering if there was a way to do something like this:
If the loop doesnt finds another child to progress then it stops, can anyone help me?
The script i have tried
local storage = game:GetService("ReplicatedStorage")
local tweenservice = game:GetService("TweenService")
local zombie = storage.VeryBadGuy
local nodes = workspace.Nodes
function spawnmob()
local mob = zombie:Clone()
mob.HumanoidRootPart.CFrame = workspace.Start.CFrame
mob.Parent = game.Workspace
moveenemy(mob)
end
function moveenemy(enemy)
local zombie = enemy
local nextnodes = nodes:GetChildren()
local finished = false
for i = 1, #nextnodes do
if finished == false then
if not i then
finished = true
task.wait(0.1)
enemy:Destroy()
break
end
local move = tweenservice:Create(enemy.HumanoidRootPart, TweenInfo.new(2.75, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Position = nextnodes[i].Position})
move:Play()
move.Completed:Wait()
end
end
end
while true do
task.wait(2.75)
coroutine.wrap(spawnmob)()
end
(if not i then is the part that will run if it doesnt finds the next child)