NearbyParts is a table of parts near the player.
Registry.HumanoidRootPart is the players HumanoidRootPart.
- 2.852 is the distance between the HumanoidRootPart and Feet (standing point) of the players. Since my game has a set height limit for players, this number works perfectly.
What this script does is grab all nearby parts top surface position and then checks if the players feet are inside of a threshold of that position. If they’re not in any thresholds, they’re most likely flying.
I already have checks in place (not shown here) to account for falling, gravity and climbing.
--# This iteration loops through all nearby parts to see --| if they're standing on a part. for _, BasePart in pairs(NearbyParts) do --# This check makes sure to not calculate terrain --| for surface position calculations. if BasePart:IsA("Terrain") == false then --# This gets the parts top surface position --| that'll later be used for threshold math. local TopSurfaceYAxis = (BasePart.CFrame * CFrame.new(0, BasePart.Size.Y / 2, 0)).Y --# This checks if the player is standing on --| a part within its threshold. if Registry.HumanoidRootPart.Position.Y - 2.852 < TopSurfaceYAxis + 1.5 and Registry.HumanoidRootPart.Position.Y - 2.852 > TopSurfaceYAxis - 1.5 then return true end end end --# If no part is being stood on, this --| function will return false. return false
Exploiters are caught if the function returns false multiple times in a row. Also I have other bullet proof anti-exploit measures in place so exploiters aren’t allowed to fly, speed hack, teleport, etc.
I’m looking for possible errors (haven’t found any yet), optimizations (especially in the math area, it looks pretty hefty) and obviously any loopholes. This script is on the server and doesn’t interact with the client at all.
Please reply with any possible concerns or potential bugs/loopholes with my code if possible, thanks!
Also I should have added, feel free to use this code for your anti-cheats as well. I’d argue that flight related exploits are the hardest to patch in a performant way and this code is incredibly lightweight.
Doesn’t work with rotated parts or wedges/ramps.
How can I get the position of the surface that's always facing up?
Doesn’t work at all with multileveled MeshParts/UnionOperations. Only way to fix this is to utilize raycasting.