Is it safe to use require() functions in parallel?

At first the answer should be yes. However, I’m using a module script to avoid :Invoke which is not safe to call in parallel lua. I have a chunk system that runs separately per player and I had to call task.synchronize everytime I wanted to grab a new chunk.

This didn’t have a dramatic performance decrease, but it said so itself that there is a slight halt when synchronizing. My chunk system is ran every heartbeat so every frame that the player enters a new chunk, it would have to synchronize for a second. Since my chunks are 10x10s, this was practicaly whenever the player was moving.

So I decided instead of using :Invoke() to grab new chunks (from a script that cached all chunks), I decided to just make it into a ModuleScript. It seems to work perfectly but I’m curious, is this a hacky solution? Or should it always have been a module script?

1 Like