I’ve been trying for a few weeks now to come up with a clean solution to efficiently detect when players enter/exit a region. Unfortunately, my best efforts have led to running some fairly heavy RotatedRegion3 methods on the game’s Heartbeat.
Since I’m currently only using this implementation for a safe zone, I’m having the clients notify the server when they’ve entered a zone, but the server still has to determine when they’ve left the zone for security reasons.
This implementation puts no load on the server when no players are in the safezones, but since the game’s spawn is a safezone in of itself, it still has to run 30 times a second, per player (at spawn) which could potentially be in the hundreds, causing the script to take up well over 20% of the server.
(my implementation is currently written in roblox-ts)
const check = () => {
if (!this.disabled) {
Players.GetPlayers().forEach(player => {
const rootPart = player.Character?.FindFirstChild("HumanoidRootPart");
let index = -1;
if (t.instanceIsA("BasePart")(rootPart) && regions.some((region, i) => {
index = i;
return region.CastPart(rootPart);
})) {
if (inRegion.get(player) !== regions[index]) {
inRegion.set(player, regions[index]);
enteredRegion.Fire(player, this.parts[index]);
}
} else if (inRegion.get(player)) {
inRegion.delete(player);
leftRegion.Fire(player, this.parts[index]);
}
});
} else
connection.Disconnect();
}
I’m just looking for suggestions as to how I could implement serversided region detection without crashing servers.