How to Terminate RunService - Render Loop?

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?

9 Likes

I soOoOOooOoooooOoooo highly recommend you use Heartbeat instead of .Stepped

I’ve done some fairly basic stuff on .Stepped server-side before and it caused some serious lag on a baseplate. Try Hearbeat :grinning:

12 Likes

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.

40 Likes

What’s the difference, anyway? Isn’t it just something about physics?

To @Beartikal,

Checking rays every frame is a naive approach. You’ll catch WAY more people lagging than cheating.

3 Likes

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.

1 Like

How do you think I could prevent noclip?

1 Like

Constantly check ping as well to get a rough average, and run intervals by that.

1 Like

How would you setup a system like that…? That doesn’t really make sense.

1 Like

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.

1 Like

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.

1 Like

It checks if Part X > humRootPart.X and < X, and the same with Y and Z. Basically checks if the part is inside the player

1 Like

Part X what? Size? Position?

1 Like

Position - Size/2 (to get all the corners of the part)

1 Like

And what parts are you checking? Everything that inherits BasePart?

That method will easily fail you for anything that isn’t perfectly rectangular.

1 Like

im checking classname Part

1 Like

You’ll probably stop some naive noclips but not teleport scripts.

1 Like

o dont worry i’ll get that covered.

1 Like

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.

1 Like

One does not simply use RunService Events on the server.

Always assume Roblox servers are running in MS-DOS, why do you think its an option on the Platform Enum?

1 Like

image

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.

image

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.

3 Likes