local cast = workspace:Raycast(character.PrimaryPart.Position, -getRayHeight(character), playerRaycastParams)
local isOnGround = cast and cast.Instance.CanCollide
if isOnGround then
playerState.lastOnTheGround = tick()
end
local distance = ((playerState.lastPosition - character.PrimaryPart.Position) * Vector3.new(0, 1, 0)).Magnitude
if distance >= 0 and tick() - playerState.lastOnTheGround > 5 then
print("The player triggered the anti-fly check!")
end
local function getRayHeight(character)
local R15 = character.Humanoid.RigType == Enum.HumanoidRigType.R15
return R15 and character.Humanoid.HipHeight + character.Humanoid.RootPart.Size.Y/2 + 1 or 3.5
end