I am currently creating a ServerScript (Anti-Exploit) that uses RunService - Stepped to check each frame for exploiting by casting rays. When a player joins, this loop starts, but when they leave it continues to run.
How can I disable this loop when the player leaves?
If I cannot, will it cause any side effects like lag, etc?
Am I going about the right way by calculating exploits every frame (RayCasts), or is that too quick?
You can terminate RbxSignal objects by using its :Disconnect() event.
For example:
local runService = game:GetService('RunService')
local Stepped
Stepped = runService.Stepped:Connect(function()
print('Printing')
end)
wait(.5)
Stepped:Disconnect()
If you are to disconnect in the middle of a connected function (anonymous function), you will have to do what I did in the example and define the variable first.
This should answer your second question.
Your third question is too vague for us to answer as far as the âright wayâ goes. Raycasting is pretty lightweight so you shouldnât really have an issue if youâre doing ~600 rays per frame. I donât have any benchmarks on it, though.
To an extent. If it isnât properly set up to not naively assume any wall must be an exploit, then yeah it would really just catch mostly laggy players.
However, when properly set up, anyone who is âcaughtâ even though theyâre only lagging must be lagging pretty bad. At that point, I basically stop worrying about those players since theyâre surprisingly so far and few between and honestly ruin the gameplay for others almost as much as exploiters do.
Ok so I now made a function that determins if a plr is inside a part that is CanCollide true, and this runs for all players and checks all parts every 5 seconds, not sure if this can cause lag tho, or if I should reduce it to a few parts instead of all parts in the game.
With what method? The effectiveness of that strategy is based on what method you used to check if theyâre inside the part, but the most effective it can be is stopping a naive noclip check.
Itâs dependant on each game and basically requires you to know where exactly to check for it and where not to. Not on computer right now and donât know how to explain it without a picture.
Hereâs a simple example. When actually making the system, you end up with more complicated situations than this. However, to explain, when youâre in the blue dot, and suddenly end up where the X is, youâve undoubtedly just walked through a wall.
This one could trigger a false positive due to really high ping, but I donât think that needs to be worried about. Again, players lagging this bad just ruin the experience for other players anyway. Itâs important for people to just remember that an automated system should never have the power to ban someone from your game.
In a case like this, itâs safe for the script to assume they didnât do anything wrong even though the ray could come in contact at the corner. This is because even players with low ping could trigger a false positive at a corner like that, and even if they did walk through the corner to get to the target, that doesnât do all that much for an exploiter anyway. So itâs fine to just ignore moves like that.