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?
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.
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.
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.
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.