The while loop that I wrote for a zombie AI stops once it gets in range of 5 studs with the player Character.
It has two conditions:
One is wait ( )
One is decendant(basically the zombie itself)
But without the zombie being destroyed, the loop stops by itself.
Here is what the code looks like:
while descendant and wait(0.1) do
if debug == true then
number = number + 1
print(number)
end
local target = findNearestTorso(OwnRoot.Position)
if target then
local p = pf:CreatePath()
local pos = target.Position
p:ComputeAsync(OwnRoot.Position, pos)
if p.Status == Enum.PathStatus.Success then
local LST = p:GetWaypoints()
if LST then
for i = 1,5 do
local WayPoint = LST[i]
if LST[i].Action == Enum.PathWaypointAction.Jump then
Droid.Jump = true
end
if debug == true then
local Part = Instance.new("Part")
Part.CanCollide = false
Part.Material = Enum.Material.Neon
Part.Size = Vector3.new(.1,.1,.1)
Part.Anchored = true
Part.CFrame = CFrame.new(WayPoint.Position)
Part.Parent = workspace
game.Debris:AddItem(Part,5)
end
Droid:Move(WayPoint.Position - OwnRoot.Position)
end
end
end
end
end
So right there is no
break or return
in this extract.
Droid is the zombie’s Humanoid and findNearestTorso returns you a HumanoidRootPart or nil.
For the debug part, basically stops generating new path indicators (Neon blocks) after it goes near the player.
For every run of the loop, the number which indicates how many times that the loop has run, will be printed.
It stops printing after they go near each other (player and zomb)
This really bothers me as a lot of my players have gave me the description of this bug but I am just not capable of soving it.
Upmost appreciation to any helping hands.
PS: loops are not being breaked properly 6 hrs after this post.