Detecting for How Long has the Player Been in the Air

Hey!
I’m trying To Get to Know For How much Time the Player Stays in the Air For.

Suppose the Player Jumps, For Some time He is in the “Falling” State Type. Is there A Way i Can Calculate for How Long the Player is Falling In the Air? (Or in the Air)

Basically Calculate the Time in Which the Player is In the Falling State Type aka Falling From a Height

Thanks for Reading! :happy3:

1 Like

you could use a while loop for this but is it really efficient?

probably use RunService with yielding to counter it and if the state changes and its ~= "Air" then disconnect the event

I commented about this in the past.
Maybe you are making a fall damage system, this is how you would do it if not, well this should also solve that issue.

This would be used if you want to enable fall damage for a certain height: h=1/2gt^2 (this calculates height)
H = Height (what you want)
G = Gravity (9.8)
T = Time from falling to landed

For time it should look like
V is your velocity you can just get from the player or calculate from the height but that seems a bit redundant.

T = V/G

Definitely look at this link, the post above mine is what you can use to detect if the player is falling or not.

2 Likes
local StartTime 

Humanoid.StateChanged:Connect(function(_, State)
    if State == Enum.HumanoidStateType.Freefall then 
       StartTime = tick()
    elseif State == Enum.HumanoidStateType.Landed then 
       local AirTime = tick() - StartTime 
       print("Was in air for "..AirTime.."s")
    end
end))

It would be something like this, havent tested it. I am currently on mobile. Tomorrow I will edit it when on PC and provide an explanation / breakdown of how it works.

3 Likes

Hey! Thanks for Your Reply!
It Works Just as Expected.

But it Also Prints In Decimal Numbers.
Is there a way i Can round off the Number to the nearest Whole?

1 Like

Nvm Found it on My Own.
Thanks for Helping!

1 Like