How use Parallel Luau with AI?

I am trying to get like 500 “dumb” zombies, fully optimized humanoids, that only try to get to the nearst player. (still working in the optimizaton)

I was suggest to research collection service and parallel luau.

But how i can implement it?

The main idea is → CollectionService:GetInstanceAddedSignal(“NPC”) → SetUpHumanoid(Humanoid) → StartAI(Humanoid) where SetupHumanoid will do one time stuff like disabling humanoids states or setting random walkspeeds, and StartAI connect some functions to some blindable events, that will be fired in loops, and when the humanoid dies, discconect the functions

The AI should only search for nearst player with a function, set the npcs[npc][target] = HumanoidRootPart to that close player, set the humanoid WalkToPart() until target is nil or dead, and set it again every time the humanoid.MoveToFinished event fires

But how implement the Parallel Luau? i should start cloning the main script and parenting it to a different actor in server script service each? I should create a new tag per new script

And when use task.desynchronize? i can use it to calculate nearst player, but is not to many math to do, i dont need it to SetUp function, and i cant set humanoid:MoveTo() if i am not runnung serial

Can someone giveme an idea how i can use this new Parallel Luau to optimize handling in mass AIs?

So Basically,

You should be using Parallel Luau for Calculations. And stuff that does not yield, when using Parallel, there are stuff that it cannot read, or deems unsafe, to check if it can be read in Parallel. It will show Read Parallelon it, which is what that means if you didnt know.

So Basically, you can then use Parallel Luau for maybe getting the the closest Player, or calculation on what the Mob must do in a Specific way, And for Serial (which is where you use task.synchronize), you would firing the functions with those calculations to update positions. And Movement, and if you want to switch back to Parallel, its as simple as task.desynchronize.

3 Likes

And what is the best to do it? with only one script and only an actor? Is bad to performance set task.synchronize and task.desynchronize too often?

Basically said it.

Roblox Recommends you use Multiple instead of one.

Only do it when nessacary, if you are using it constantly, you might not need to use Parallel Luau.

1 Like

Thanks for the awnsering! maybe i dont need the parallel luau, the main problem is the rending and physics drop, in the server and in the client, especially when too many zombies stick together (still looking for a solution to that)

I will set your awnser to solution to close the post

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.