parallel luau is hard
so i’m trying to make a pathfinding system to where it uses parallel luau and the problem is. i have the task.desynchronize()
function in the script.
my game will have around a bunch of npcs / citizens. and other threads will be happening. making frames render really slowly. so i’m using multi threading to separate the processes
but every time i use that. inside of the module. another module is a pathfinding module that actually creates the paths. and i keep getting this error
Function Path.ComputeAsync is not safe to call in parallel - Server
so i’m trying to see how i can make it to where it can compute the path without giving the error.
i have heard using a bindable event. or using the new actor:SendMessage function with the topic and the data.
if that’s the only way. can someone show me a example on how i will do that. some code at least.
here is the code by the way.
-- the code that executes the path
local x = math.random(-20, 20)
local z = math.random(-20, 20)
local pos = humanoidRootPart.Position + Vector3.new(x, 0, z)
task.desynchronize()
path:Move(pos)
-- what path:Move does
function path:Move(position)
local model = self.Model
local humanoidRootPart = model.HumanoidRootPart
local humanoid = model.Humanoid
local path: Path = self.Path
path:ComputeAsync(humanoidRootPart.Position, position)
local waypoints = path:GetWaypoints()
for i, waypoint: PathWaypoint in ipairs(waypoints) do
if self.Ended then
break
end
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end