How can I improve my Anti-Cheat?

Hello, everyone! We’re developing a game, and on Monday we had a playtest with about 6 people joining. I have implemented some basic Anti-Cheat such as Anti-Flying, Anti-Teleporting, etc. During the playtest one of the players got banned from “flying”, he was exploring an area where there was huge mountains and stuff. And while he jumped, he got banned. I have already tested this and found no issue with getting banned. How can I ensure that people don’t get banned because of this, and just overall improve the Anti-Flying? Here is the script:

Anti-Flying Script:

local Players = game:GetService("Players")

local RemoteEvent = game.ReplicatedStorage.MythicAntiCheatEvents:WaitForChild("BanPlayerEvent")

local function Ban(Player : Player)
	Players:BanAsync({
		UserIds = {Player.UserId},
		ApplyToUniverse = true,
		Duration = 60,
		DisplayReason = "MythicAntiCheat detected potential flight exploits.",
		PrivateReason = 'The player was suspected of flying.',
		ExcludeAltAccounts = false,
	})
end

local MAX_AIR_TIME = 5
local CHECK_INTERVAL = 1

local function TouchingGround(root)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = {root.Parent}

	local raycast = workspace:Raycast(root.Position, Vector3.new(0, -4, 0), params)
	return raycast and raycast.Instance ~= nil
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local root = character:WaitForChild("HumanoidRootPart")
		local humanoid = character:WaitForChild("Humanoid")

		local LastTouchedGround = tick()
		local InAirTime = 0

		while character.Parent do
			task.wait(CHECK_INTERVAL)

			if TouchingGround(root) then
				LastTouchedGround = tick()
				InAirTime = 0
			else
				InAirTime = tick() - LastTouchedGround
			end

			local velocity = root.Velocity
			local isMovingUp = velocity.Y > 0
			local isNotFalling = humanoid:GetState() ~= Enum.HumanoidStateType.Freefall

			if InAirTime > MAX_AIR_TIME and isNotFalling and isMovingUp then
				Ban(player)
				print("Banned player for flying exploits.")
				break
			end
		end
	end)
end)
2 Likes

BANNING people for being in the air for too long is one of the absolute WORST ways to go about detecting flying. Only kick them, false positives can and will happen with the method you’re using. Instead, you can detect abnormal velocities that get added to the character on the client, such as bodypositions or bodyforces. Anything like that

2 Likes

Exactly. If you wanted, you could setup logs externally that the game just sends webhooks to for this.

Have you looked at exploit source codes? Flight Exploits usually use BodyVelocities/BodyGyros. That would be more efficient than just checking whether people are in the air for too long.

Try look at Infinite Yield’s source code. It’s probably the most widely used exploit script.

Reference for flight:
Fly: Line 6904
CFrameFly: Line 7158 (use of CFrame manipulation to fly)

id also suggest adding a check to see if the humanoid state is “platformstand” since i think flyhacks also put the player into that state if i remember correctly