Anti fly script

Its the first time I’ve done something like this, an anti fly exploit script, which works by going through all player’s characters every frame, shooting a raycast directly to the ground checking if it hits anything. I have no idea where to go with my code. Please critique it and see if it has any flaws. Thanks!

--// Variables 
local players = game:GetService("Players")
local run_service = game:GetService("RunService")

--// Functions

local function flight_check(plr)
	if plr.Character then
		local humanoid_root_part = plr.Character:WaitForChild("HumanoidRootPart")
		print(humanoid_root_part.Position)
		local ray = Ray.new(humanoid_root_part.Position,Vector3.new(0,-15,0))
		local hit = game.Workspace:FindPartOnRay(ray)
		if hit then
		else
			plr:Kick("Caught Flying")
		end
	end
end

--// Main

run_service.Heartbeat:Connect(function()
	for _,v in pairs(players:GetChildren()) do
		flight_check(v)
	end
end)
11 Likes

This will kick anyone if they get flung or anything weird happens, say they are laggy and the map doesn’t load etc… you should have multiple measures;

These should help you better understand it, don’t go straight to kicking as well. It should be a building up and often enough teleporting them back or resetting their character is enough to deter exploiters.

It also must be stated that you’re using a local script and that can be disabled by the exploiter, anything on the client can be altered and changed in any way. So read up on these posts, they should really clarify how exactly it happens, ways to patch and handle them.

12 Likes

this may not help at all or something, but with fly scripts the exploit puts a part under the player, when the player jumps the part stays under them, which makes them fly.

maybe the best way is to cast a ray on the client and send the server information about what they are standing on every 5 seconds.
Then have the server cast a ray once the information is given. if they both are the same,the player isnt flying. if they are different then they may be flying.

if the exploiter disables this script, then kick the player for not sending the server information about what the player is standing on after a set time, maybe 10 seconds so that people with bad connection dont get kicked

but hey, im not really sure myself lol. maybe it will work

1 Like

Never trust the client. You shouldn’t rely on a LocalScript to do your exploit checks; an exploiter could just send fake data through. Also, with a bad connection, something like walking out of a house could get you kicked with this system (client says it’s on the floor of the house, by the time server receives it they’re out on the steps or something).

6 Likes

Not a good idea. I recommend you look for Gyros being put in the player, as this is how a player flies. And how many exploits make them fly, unless you are using gyros for some reason in your game, I highly recommend to do this.

1 Like

This wouldn’t work. Exploits create things client-side that the server can’t see and you definitely shouldn’t be patching exploits client-side. Server-side Position/Raycast checks are the way to go.

1 Like

my own and here’s what i got

local player = game.Players.LocalPlayer
local sitcount = 0
local maxsit = 2 

spawn(function() 
	while wait(1) do
		if sitcount > maxsit then
			player:Kick('Kicked for Fly Hacks')
		end
		sitcount = 0
	end
end)

player.CharacterAdded:connect(function(Character)
	Character.Humanoid.StateChanged:connect(function(oldstate, newstate)
		if newstate == Enum.HumanoidStateType.Seated then
			sitcount = sitcount + 1
		end
	end)
end)

another way put a big part in sky and if theirs no thing ur game that can make a player get that high in game then kick player if they touch part

Simple code hack

There would be a problem with that. What if a player gets flung up to the part when they aren’t flying. Also sometimes exploiters don’t even fly that high.

1 Like

I’m sure they will fly that high also,There’s a way to prevent flinging
Ragdoll system prehaps

I know that it has been an extreme amount of time since this has been posted. But I do have my own anti-exploit type of thing for flying.

Finds name only:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

character.HumanoidRootPart.ChildAdded:Connect(function(new)
	if new.Name == "BodyGyro" or new.Name == "BodyVelocity" then
		wait()
		game:GetService("Players").LocalPlayer:Kick("\nFailure to find security key")
	end
end)

Detects anything with specified ClassNames:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
character.HumanoidRootPart.ChildAdded:Connect(function(new)
	if new.ClassName == "BodyGyro" or new.ClassName== "BodyVelocity" then
		wait()
		game:GetService("Players").LocalPlayer:Kick("\nFailure to find security key")
	end
end)

Additionally, you can replace the part where it kicks with a replicated event.

4 Likes

Does anything detrimental happen to a player’s account when they get kicked from a game? im just wondering if one could use kicking as a game mechanic

If someone gets kicked from a game nothing happens to their Roblox account. It simply just removes them from the game if that is what you are asking.

1 Like
  • You could use many invisible,non colide-able parts with TouchEvent detector.
  1. Place them all arround your map and in places normal players can’t get to witouth flying.
  2. After that, if your game has no player-to-player colide, you can make a script that kicks every player that touches those parts,but also that checks if the player is not coliding them, every 3 or 5 seconds.
  3. Also add in another hidden script,or just a normal script with a strange name(So no one gets it is the anti-fly) a checker so if the player isn’t anymore sending information about is he touching or not those invisible parts, he gets kicked or banned,at your choice.

Ps: I am a beginner scripter in RobloxLua,so sorry if in my words there was something illogic.

You don’t need to rename “a normal script with a strange name(So no one gets it is the anti-fly)”. If you simply put the server Script in ServerScriptService, it will not replicate and malicious users will have no normal method to disable/manipulate it.

Having server-sided boundary checks for areas that are inaccessible to regular players is a sound idea. However, being ROBLOX, glitches do sometimes happen where a player might accidentally stumble into these areas. Rather than punish the player (ie; kick/ban), you could simply teleport the player to a nearby known valid location.

1 Like

You don’t need all this code you just need to check when Humanoid.Changed is fired. Then check if PlatformStand = true kick them because all fly scripts i’ve seen have used platform stand

This is objectively false, as there are tons of methods to “Fly” without PlatformStanding the Humanoid. Rather than try to detect very specific changes to a humanoid (which really is a side-effect of certain cheat implementations), it is better to do a comprehensive check of the Character position itself, as this defeats all methods of “Fly” cheating.

1 Like

If your game has no sort of fast traveling like dashing or so you can do a :GetPropertySignalChanged() on the Velocity of the Character PrimaryPart and see if it goes over a certain limit because there are many ways to “Fly” which some includes BodyGyro and BodyVelocity and others may include other methods.

3 Likes

Hey, where exactly would I place this code? And in a Server Script or local script? Sorry im quite new to scripting

It’d be a local script, place it in starter character scripts if I remember right