What is the best way of going about checking the players magnitude to a part every heartbeat

(note - not looking for any code, just an answer)

I’m working on a Capture System for a group I’m apart of and I’m wondering which way would be the best to check the magnitude of the player (performance wise) (any other solutions are welcome)

From the Client

  • Each heartbeat check magnitude
  • If in range invoke the server
  • Server does sanity checks assuming the client is lying

From the Server

  • Each heartbeat loop all players that are on a team accessible to the capture system
  • Check the magnitude
  • Add points where needed

My only issue with doing from the client is the fact that they’re going to be sending the server requests every heartbeat. (which can be heavy on performance)

Maybe a wait or debounce on the client?

Client can still send remotes calls using an executor.

I’m probably just going to do this in the server, check each second and then add on one point. I just don’t know if this would still be heavy on performance.

Depends if you want to check for the player’s magnitude in multiple scripts. Take NPCs for example. People use magnitude to have the NPC follow the player, but they have multiple NPC scripts constantly looping through the workspace for the character on the server, making a lot of server lag.

I’m only having one script that does this.

If the server is going to check each player every frame, there is no need to send anything from the client to the server, the client code–if it exists at all–is just to make the game feel more responsive.

The alternative it to have the client checking distance, and sending an event to the server any time the player goes into or out of the proximity of the part, not every frame. In the case, the server will just repeat the distance check when it gets the events to validate them, and the server will not run the code every frame.

1 Like

What I’ve got right now is every second the server is checking the distance of each player. (each second a maximum of 2 points can be awarded)
Will this still be memory dragging?

A second is certainly fine, but at this point I’m concerned that the delay is too long (it might not be, I just figured that there’s a chance of false positives) . It’s a choice between functionality and performance, so it’s often challenging to satisfy both. :person_shrugging:

2 Likes

I’ll see how it goes by the server and if it still has performance issues I’ll check every 2-3 seconds but up the points it gives you.

Thanks for the response and everyone else that responded to this thread.

How many parts are you checking player distances to? If it’s fewer than 100 and you’re having “performance issues” with running this check just one time per second, there is either something very wrong with how you’re doing it, or you’ve got an unrelated performance issue elsewhere in your code. You should be able to check the distance from each player to 100+ parts, on every single heartbeat without any issues. What measurement are you looking at that you think is indicative of a performance issue? Server heartbeat rate? Script execution time?

2 Likes

I’m looping through EVERY player. Which at most times is 30-65

I’ve added this in and looping each second and I’m having decent performance so I guess that’s good.

This never should’ve caused performance problems in the first place. You can safely do this at 60 hz. It should take roughly 1/10th of a millisecond.

What I was asking was, for each of these 30 to 65 players, how many items are you checking their distance to. i.e. what is the total number of player:DistanceFromCharacter checks. Last time I checked, a Roblox server could to roughly 5000 DistanceFromCharacter + conditional comparison checks per millisecond. So checking 50 players and 100 points is no problem. If you had nearer to 1000 points of interest, the execution time becomes significant enough to warrant breaking it up. And by breaking it up I mean distributing the work over multiple frames, not just trying to do it all at once but less often; if the calculation is too much to do on one frame, doing it less often just means the server hitches less often, it doesn’t actually stop it hitching.

1 Like