Detect for how long player has been falling

Your airtime variable is a local inside of the if statement right now. It will not work outside of that. So make the variable earlier in the script

1 Like

When you jump something in the humanoid gets enabled, I’m not on computer so I’d wouldn’t be able to check although you can.

Test the game, go to your humanoid and jump and see what enables.

Free falling enables. Thats why The freefalling statement is there

How? SInce its already in the front of AirTime

Or you may be able to just change it to

That wouldnt work cuz I need to detect how much time or the sound will play even when the player just normal jumps

You are not waiting .5 seconds the script ends quicker than when you check if its .5 seconds. You should use wait() or delay() i’m not sure which is better in this case.

Right, but it’s just 0.5 seconds, when they jump it’ll past that very quick so it’ll be better to play the sound automatically after jumping, no?

Or you can just add this variable

 local AirTime = tick() - StartTime 

above the sound variable?

It kinda works but when the player lands it stops for a second then starts again. Its better to detect for how long.

I did this:

local Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://6960193959"
sound.Volume = 3
local StartTime 

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

but it doesn’t play the sound. even if I’ve been falling for more than 0.5 seconds

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")

local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://6960193959"
sound.Volume = 3

local StartTime 

Humanoid.StateChanged:Connect(function(OldState,NewState)
	if NewState == Enum.HumanoidStateType.Freefall then
		StartTime = tick()
		delay(.5, function()
			if tick() - StartTime >= .5 and Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
				sound:Play()
			end
		end)
	elseif Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
		sound:Stop()
	end
end)
2 Likes
-- local script

local ps = game:GetService("Players")
local lp = ps.LocalPlayer

local TimeInAir = 0

while wait() do
  local ch = lp.Character
  if ch then 
   local c = RaycastParams.new()
   c.FilterType = Enum.RaycastFilterType.Blacklist
   c.FilterDescendantsInstances({ch})
   local r = workspace:Raycast(ch.HumanoidRootPart.Position,Vector3.new(0,-10,0),c)
   if not r.Instance then
   TimeInAir = TimeInAir+1
    -- There is nothing underneath, assume in air.
   else
   TimeInAir = 0
    -- Not in air.
   end
  end
1 Like
local Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local lastFall = 0

local sound = Instance.new("Sound", game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart"))
sound.SoundId = "rbxassetid://6960193959"
sound.Volume = 3

Humanoid.StateChanged:Connect(function(_, State)
	if State == Enum.HumanoidStateType.Freefall then 
		lastFall += 1
		local myLast = lastFall
		
		delay(0.5, function()
			if myLast == lastFall then
				sound:Play()
			end
		end)
	elseif State == Enum.HumanoidStateType.Landed then 
		sound:Stop()
	end
end)
1 Like

If you want to be fancy and want the sound to fade in :stuck_out_tongue:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")

local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://6960193959"
local Volume = 3

local StartTime

Humanoid.StateChanged:Connect(function(OldState,NewState)
	if NewState == Enum.HumanoidStateType.Freefall then
		StartTime = tick()
		delay(.5, function()
			if tick() - StartTime >= .5 and Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
				sound.Volume = 0
				sound:Play()
				for count = 1,10 do
					local Incr = Volume/10
					sound.Volume = sound.Volume + Incr
					wait(0.1)
				end
			end
		end)
	elseif Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
		sound:Stop()
	end
end)
1 Like

Thank God! I was trying to script a Tween to make it fade in. Thank you! Life saver

1 Like

Ahaha I thought about that too but a whole tween? Using a for loop way easier!

1 Like

Question? How do I make it get louder Slower? I tested and it was to fast and I want to slow it down a bit but without the sound getting choppy.

Increase the wait() or the amount of times it gets louder

so

				for count = 1,20 do -- Change this to make the amount of times you're making it louder
					local Incr = Volume/20 -- and change this ^
					sound.Volume = sound.Volume + Incr
					wait(0.1) --Change this for the amount of time you're waiting between everytime you're making it louder
				end
1 Like

Oh yea don’t forget to add

		sound.Looped = true
1 Like

If the player is currently in freefall and you know it, there is a simple way that uses physics to determine the time the player was freefalling.

local freefallTime = humanoidRootPart.AssemblyLinearVelocity.Y / workspace.Gravity
1 Like