How to use global variables with parallel luau

Recently I decided to use actors for my project, I mainly use things like shared to pass data globally on both client and server which saves me and my team lines of code to transmit, and also is responsible for a lot of our player based variables.

Recently I have decided to utilize actors to make our experience run smoother, but have met an issue: If a script is placed under an Actor, they will not be able to see shared that other local scripts that aren’t under an Actor can see, same way scripts outside cannot see any changes done to global variables inside of the script inside of the actor.

Example:

-- Script under an actor
shared.Modules = {}
shared.Modules.Test = require(...)
-- Script that has a normal parent
repeat wait(.25) until shared.Modules -- Continues forever as it cannot see changes done to global variable in prior script.

Is there any sort of fix to this without forcing us to re-write entire systems? I understand that whole point of this is to use different cores of the device and may not have the access like rest of the threads.

You can’t, for now. Whenever you require a module inside an actor script, it will re-execute the entire module so that each actor has its very own module environment (which can be devastating to memory usage if the modules are initializing something big like a lookup table). This is done to abide by thread safety rules.
Cross-thread environment is something that Roblox is still working on, but for now, the only feasible way for different actors to communicate with one another is via events, but that means bandwidth bottlenecks.

2 Likes

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