So I need to make a system where a script detects what area you are in.
Seems simple enough, but this information needs to be replicated to the server.
So my question is:
Is it wise to call :GetPartBoundsInBox OR :Raycast every 0.2 seconds or so from the server per character?
(regions with :GetPartBoundsInBox or just downcasting with :Raycast)
Im not sure what the performance of either of those are, which is why Im asking this
Thanks in advance
EDIT: Alternatively, I could call :GetPartBoundsInBox on the server FROM THE REGIONS every half a second maybe.
There obviously wont be as much regions as players, and I could detect a couple of players per region as well.
If the region/ray is relatively small, you shouldn’t have any problem. Also depends on how many characters can be on the server. Either way I recommend using Heartbeat and os.clock() instead of loops (if you thought of using loops, of course).
The ray should be relatively short since its just a downcast from your torso to the ground, the regions would be a bit bigger, but still nothing crazy.
There is a maximum of 20 players per server currently
I don’t think it would cause massive lag issues. If your game does not have unoptimized chunks of code, and it’s not a big game, you won’t have issues. It also depends on the rest of the code you’re executing inside your loop or heartbeat connection. As long as it’s nothing too heavy you’ll be fine.
Use a short downcast and Heartbeat, it’s computationally inexpensive. Broadphasing every frame with GetPartBoundsInBox will probably be a whole lot more expensive for your use case and especially if you have multiple regions you need to do this over. Better to base the information off of the character’s current position than to have a background poll of every possible area.