I am working on the server side portion of my game, where security checks take place.
On the server, I need a loop constantly checking every players position and velocity. ( Players are velocity controlled spheres. )
As far as I am aware, physics replicate faster than remote events can arrive at the server, so I need to be able to detect when a player starts to move on the server using a loop, and then verify that movement if the remove event makes it to the server.
This means I need some tolerance, say, “if the remote event doesn’t arrive in 3 seconds, reset players position”. But then theres a problem.
If I use a for loop within a while loop to iterate through all the players, but each player needs 3 seconds to wait for a remote event, then the whole loop slows down. Keep in mind, this needs to be done fast.
( Like, every player has their own coroutine fast. )
Avoid remotes and usage averages instead of instantaneous data. Your remote introduces two bottlenecks: depending on the client and network traffic. Those two alone diminish the effectiveness of your system, especially the former option.
Instead of relying on waiting in each loop iteration which effectively prolongs your checks, instead use os.time to compare the time that the server begins an action and when the condition is completed.
If your intention is to prevent movement-based exploiting, you’ll have to think outside the box and think of different implementations. You’re running into anti-patterns with your code already, so you’ll want to learn to avoid those.