Anticheat to detect if player owns area in simulator games

So I want to make an anti-cheat for my simulator game. The game has 5 areas which you can buy with in-game currency. So now, how do I check if exploiters/glitchers enter an area they don’t own and teleport them back. I was thinking of using something like this:

local function anticheat()
   while true do
      if ... then
         --Teleport player back to spawn
      end
   end
end

for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
   coroutine.wrap(anticheat)()
end

But that would reduce performance because we are checking every frame, so is there any other way that would work?

1 Like

Try adding a Bool for if they own the area.

Example:

If BoolValue.Value == false then
       -- Move the player

(Not sure how to move the player yet scince I don’t know your full code :slight_smile:

That isn’t my question. My question is if there is an alternative to using while loops to check.

Ohh, I see now. Sorry about that.

I wouldn’t create a coroutine for each player, but simply iterate over every player character each loop. This is probably the best way of doing this as character touch events rely on the client to be telling the truth. These calculations aren’t expensive, but you could always reduce the frequency at which you check. I suppose it depends on the type of game, but I don’t see why this needs to be checked every frame rather than once every second or so.

Also if you want to use a cheaper form of hit detection than something like workspace:GetPartsInPart(), you could simply use raycasts and exclude everything that isn’t either the player’s character or those zones (if you’re using a part for those areas). The ray won’t hit anything if it’s already within the part. Alternatively, you can rely on some math and distance checks.

1 Like

Okay thanks! Also for checking if the player is inside an area, should I use .Touched events?

The issue with Touch events is that it depends on the network owner. Player characters are owned by their player’s client of course, and therefore can lie about if they touched something or not. In fact, it’s as easy as deleting those touch parts client-side, and now it’ll never trigger a touch event for the parts that were deleted.

Okay… so is there any other alternative for .Touched?

The easiest method would be to use GetPartsInPart, but it is a bit costly compared to doing simpler checks such as Raycasts or distance checks.

Although I’ve recently seen another method to still use Touch events, where you basically create a server-side part with no collision that gets moved to the player’s root part CFrame in a loop, then use that part to detect hit detection. But that part has to be unanchored for Touch events to work and you need to set its network owner to nil so that only the server has control over it.

1 Like

Thank you! By chance is there any Devforum post that covers the second method you talked about? If yes then can you please share the link?

There’s a number of posts that talk about various methods such as these:

But what I mentioned can be found somewhere in this video:

I don’t think he actually shows any code related to it, but mentions it as a method. But you essentially just create an unanchored and non-collide part, set its network owner to nil, and then constantly loop its position to the player character’s root part’s position. Then you can use that part for touch events.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.