How would I create an anti-cheat for an FPS game

  1. What do you want to achieve?

I’m making an FPS game but don’t know how to make (anti-noclip and not anymore) anti-aimbot

  1. What is the issue?

I don’t know how to detect if a camera’s direct moved too fast aka locking onto a target behind the camera instantly. My aimbot script I designed for the game didn’t print “aimbot”

  1. What solutions have you tried so far?

I searched on devhub and no answers, so I’m asking on devforum.

so far this is my local script it isn’t finished

  local obj = script:WaitForChild("OriginalScript").Value

game:GetService("RunService").RenderStepped:Connect(function()
	local s,e = pcall(function()
		obj.isNotDeleted:FireServer() -- make sure script not deleted
	end)

if game.Workspace.CurrentCamera.CFrame >= lastCameraPos then
 print("aimbot")
end
lastCameraPos = game.Workspace.CurrentCamera.CFrame
	if e or obj == nil then
		game:GetService("Players").LocalPlayer:Kick("Anti-Cheat detected cheat.")
	end
	for i,v in pairs(script.Parent:GetChildren()) do
		for o,b in pairs(v:GetChildren()) do
			if b:IsA("BodyMover") then
				game:GetService("Players").LocalPlayer:Kick("Anti-Cheat detected ''BodyMover'' in ".. v.Name ..".")
			end
		end
	end
end)
2 Likes

I suggest adding humanoid stuff such as MaxHealth and health to detect if there messing around with that

1 Like

You are literally detecting if the client didn’t move it’s mouse or moved it’s mouse/camera, that’s so horrible…
Detecting aimbot is just a no, unless you prefer writing an AI and train it to detect that (in most cases it’ll even fail).
Client input cannot be detected as cheating as far as aimbot goes, since again, they also do look legit in a way to the game (oh they just moved their camera or they just moved their mouse, that’s normal.)

Instead of throwing your production time on attempting something so futile why not work on more server security? like confirming shots that are sent from the client or checking if the player is walking faster than they’re supposed to, or they’re cheating in general.

Do not waste your precious development time on stuff like this, of course, after you finish all the stuff I listed above, then maybe you could attempt some kind of client anti cheat for extra security.

1 Like

Anti-cheat in LocalScripts is futile, as an exploiter can easily delete any anti-exploit scripts running on their client. The rule of thumb is: don’t trust the client. Anything that runs on the client is vulnerable to exploiters. Since FPS games require precise information from the client to calculate movement and shooting accurately, this makes anti-cheat a difficult problem to solve without compromising gameplay fidelity in some respect.

Secondly – and this detail is irrelevant in lieu of what I just said – you can’t compare CFrames using operators like > or >=. Instead, you would want to track the horizontal angle in the player’s CFrame using CFrame:ToOrientation(). I recommend reading up on CFrames if you want to get a better idea of how to work with them.

2 Likes

My localscript fires an event to make sure the script isn’t deleted. the server script is in the character and another server script detects if the server script or the localscript in the character is deleted then kicks the player. also is this what you mean? https://gyazo.com/51dbb322968bd7509e2fea439828c490

1 Like

Okay, I thought LocalScripts didn’t replicate to the server, but it seems I was wrong.

However, this doesn’t really change what I said, because you still can’t trust the client. In principle, an exploiter could use any number of methods to halt the execution of a LocalScript on his machine without the server (or their own Roblox client) ever having information of this. Because it is their PC, in principle they can do anything to the code running on their machine, or even run their own code.

I should mention that I am not speaking from my own expertise, but from common wisdom. This is a discussion that’s been had many times on this forum, not to mention by game developers in general. I refer you to what Roblox’s Senior Software Engineer @Tiffblocks said in this other thread:

All that aside,

Yes, that’s essentially what I’m referring to. You would want the character’s rotation about the Y axis.

3 Likes