When calling task.synchronize() inside a module that is under an actor after calling :BindToMessageParallel(), the engine throws the following error despite the module being a descendant of an actor.
task.synchronize() may only be called from a script that is a descendant of an Actor - Edit
Script ‘cloud_15951241108.Plugin.HeatmapRenderer.Workers.Actor.Worker’
This issue started occurring suddenly without any update to the plugin.
Code snippet:
script.Parent:BindToMessageParallel("EventName", function()
-- Do work
task.synchronize() -- Error
-- Fire bindable event to top level controller
end)
We recently enabled an error which is likely to blame for this issue. We will disable that error since it is causing problems. Please let us know if the issue is resolved. It will probably take just over an hour for the issue to resolve.
The error has been disabled for now. However I’d like to investigate this issue further to determine if the error was occurring because of a legitimate issue in the experience, or if Roblox itself is at fault.
Would it be possible to get a copy (possibly a simplified copy) of the place file that was generating this error via private message?
The error no longer appears, but we’re now seeing a warning in its place.
task.synchronize() should only be called from a script that is a descendant of an Actor
We’re currently using a workaround to get around this error/warning:
local Actor = script.Parent
Actor:BindToMessage("Finished", function(...)
ResponseBindableEvent:Fire(...)
end)
Actor:BindToMessageParallel("RenderChunk", function()
-- Do work
local data = 1 + 2
Actor:SendMessage("Finished", data)
end)
For more context of where we’re seeing the error without sending the entire file, we’re running these actors inside of a plugin. A single script sits top level which is purely for requiring the modules that act as individual services. One of those services is our heatmap rendering pipeline, which in a module creates actors, clones the “Worker” file under the actor, then requires it so its ready to handle render chunk request.
Let me know if I can help provide more information.
I looked into some plugin source which I think matches the plugin causing the error. From what I can tell, the way it clones and then requires a ModuleScript in an Actor is causing the issue.
The error/warning messages for Parallel Luau try to describe any issues, but sometimes the description isn’t precise enough to fully convey the problem.
In the case of the plugin it looks like a single script clones the ModuleScripts under Actors and then requires them. The issue here is that even though the ModuleScripts are located under an Actor, the thread that is trying to call BindToMessageParallel actually belongs to the main script that is cloning all the Actors. So instead of the callbacks being created on separate Actor VMs/threads I think they are all getting created on VM/thread of the main script thread.
If possible could you create a Script (not a ModuleScript) under each Actor that is cloned. That Script can then include the ModuleScript. Requiring the ModuleScript from a regular Script, ensures that a thread on an Actor VM is used. Basically ModuleScripts are always on the same VM that they are required from, but a Script or LocalScript will use an Actor thread if placed under an Actor.
If at all possible, please try to make this change. If it is successful then the warning message you are currently seeing should no longer occur. We would like to switch this warning back to an error soon, but of course we want to limit any issues for our creators as much as possible.
If you need any help making this change and have more questions, please don’t hesitate to reach out to me.
This makes sense. Although during our initial development we did see that performance improved significantly when using the modules with the actors, leading us to believe that parallel Lua was working correctly. It’s worth mentioning that when this was developed, scripts with Plugin context wouldn’t run when enabled.
After switching to the scripts instead we now see an even more significant performance boost, thank you for the callout.
Additionally, wouldn’t it make sense to add an error for :BindToParallel as well for this context? It’s misleading otherwise since devs would assume their code is running in parallel when in reality it isn’t.