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)