I’m experimenting with OOP, and so far everything goes well, I made a basic zombie that uses pathfinding, however. I need to add a delay to their movement to make them more erratic. I’m using task.wait(0.05) after it , and this causes one zombie out of a group of 4 to move only, then when that zombie’s done, the next one moves, etc. This does not happen at all when I remove the wait so it is not the pathfinding.
More specifically, coroutine.wrap. Example:
for i, v in pairs(zombies) do
coroutine.wrap(function()
--pathfinding
end)()
end
Use coroutines if you are planning to yield the code in an event-based system. If you are planning to run the code forever, then use task.spawn()
task.spawn(function()
while task.wait(math.random() * 4) and zombie.IsAlive do
-- code
end
end)