Anti-Fly Script, Probably?

Hello everyone, so today I was working on an anti-fly script if I can call it like that cause I am only checking the Y axis. I also added an counter so we could somehow make sure they were exploiting. Here is my code.

--Credits to ArticGamerTV please :3
local MaxY = 20 -- Change this to maximum Y position
local MaxCounter = 5 -- Change this to maximum counter (caughts)

local ValueS ="IntValue")
ValueS.Parent = script
ValueS.Name = Player.Name

   while true do
local function YaxisExists()
   if Character:FindFirstChild('HumanoidRootPart') ~= nil then
local Yaxis = Character:FindFirstChild('HumanoidRootPart').Position.Y
 return Yaxis
  return false

local success, message = pcall(YaxisExists)

if success ~= false then
	 if message > MaxY then
		ValueS.Value = ValueS.Value + 1
	     if ValueS.Value < MaxCounter then
		  warn('Player: '.. Player.Name .. ' was caught exploiting')
		  Player:Kick("We caught you exploiting")
		  --Add here things to happen once player is kicked or in PlayerRemoving function


I mean if you create an script in ServerScriptService and add this script in it I think it should work correctly cause we are not using any clients (LocalScripts). In my opinion this solution should probably work somehow but I am pretty much scared of server performance cause of checking that many values at the same time. If there is a better solution to do this feel free to reply. I also had an idea of adding ban but I would have to add Datastore, this would take time to make so I am asking on this forum if this is an good idea of getting exploiter or not, before I do it.


My main issue is your MaxCounter. Instead of counting how many times a player went out of bounds the entire time, it should divide the number with their playtime. It is not uncommon for players to spend over 5 hours in a game, so it is good to consider how many times they get caught during a time frame.

I see a weird syntax with that while loop. I don’t understand what the random value is for. Position checks are fairly light on the performance, so making them per frame instead of giving the exploiter 5 seconds to return to a safe space would be better.

You should also force the character back into the max height with a 0 velocity.

The YAxisExists pcall is pretty much useless as it will never fail. The function itself is also somewhat useless as it only contains 3 lines.

This also won’t stop them from flying. They can go 100 studs/second at the height of 19. Check the velocity’s magnitude. Check if their vertical velocity changes above and below zero too many times between ground touches (to avoid detecting bounces), as well as a non-changing Y speedm


I will definitely add an BoolValue so it will check how long they were in unrestricted area also an parent on intvalue counter in it which will after they come in safe area change boolvalue to false and counter to 0. I made random value so it makes different time on each caught. If I would make max hight velocity of 0 player won’t be able to even jump. YAxisExists function is not really useless as it cannot find HumanoidRootPart once player is kicked cause we are using while true do. I should caught them flying cause player will go above some Y axis value probably. I wasn’t really careful about what if they fly but on normal height. That’s the main problem but I will caught many exploiters probably.

What I am saying about the YAxisExists function is that it could be easily replaced with an if statement.

local message
if Character then
   local hrp = Character:FindFirstChild('HumanoidRootPart')
   if hrp then
      message = hrp.Position.Y

if message then

Also, as I already said, you should check per frame instead of intervals. It is impossible to check whether the player is flying if you just look at whether they are above the set limit.

1 Like

I know but I like to have complicated scripts for other people to understand it harder :shushing_face:
I’ll use check per frame in updated version of course.
I really do appreciate your help thought. :slightly_smiling_face: