Hello everybody, recently I wrote a module about regions and have wanted to discuss methods of using it.
In the module I create a class for each part thats requested through the module and have renderstepped loop run to detect if user ever walks inside one, now since regions always require update to them and I can’t have any touch events to rely on to fire these connections would instead appending all parts into a table and then looping the table through 1 renderstep be a more efficient method than for example 10 render steps all running at same time for each part requested?
I do something similar with aggro code, but I also keep a table of who is in what region, and only check those players in that region.
10 regions/parts and 10 players shouldn’t bog down the system, but 100 regions/parts and 50 players (60 times per second) will be a problem if you don’t have a plan.
The fact that you even use RenderStepped here makes it immediately bad, use Heartbeat instead. RenderStepped should only be used when you’re updating the camera, a property of the character (e.g. CFrame or transparency) or if you genuinely have a use case for something needing to occur before a frame renders. Computationally expensive operations in a RenderStep may negatively affect performance, even significantly.
Also, ideally, it might be better to stick with one Heartbeat. You can design a system around hooking tasks to be executed during that frame. For example my experience has a round manager that creates one Heartbeat event and other scripts use a Heartbeat method that will get called as opposed to having a connection per script that needs to do something with Heartbeat.
It’s recommend for camera/character model use specifically, outside of that your better options would be heartbeat/stepped or just a generic while task.wait(), do/while wait(), do/while true do loops.