Detect Humanoid root part Y velocity

So I made this script to detect for how much time the player has been in the free-falling state so if they jump off of something it would play a wind sound. but the only problem is if the character is falling forward so a dash forward their state would be free fall so it would trigger the sound. Is there any other way to make the sound play only if the player’s Y velocity is higher than a specific number? This is my script that uses free falling:

local SoundService = game:GetService("SoundService")

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

local sound = SoundService.Wind
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,15 do
					local Incr = Volume/15
					sound.Volume = sound.Volume + Incr
					wait(0.1)
				end
			end
		end)
	elseif Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
		sound:Stop()
	end
end)

Example of my game:

2 Likes

You could have a bool value called isDashing and set it to true whenever the player is dashing.
And after that modify the if statement of your script from this:

to this:
if NewState == Enum.HumanoidStateType.Freefall and not isDashing then

1 Like

My guy. I would never thought about that. Life saver :flushed: (Im not being sarcastic)

Or yk… Could just get the velocity :slight_smile:

game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity.Y
1 Like

How would I check if the Y velocity passes a certain number so it can start the sound?

if game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity.Y > 10 then

end

Something like that.

Mhm. Also for debug reasons How would I get the Y velocity? like where is it located in properties?

You can just print it in a loop. But I’d rather stay with @3LettrName solution.

Velocity Is apart of the Hidden Properties but can still be used inside regular scripts, As Neo stated stick with 3Lettr’s Solution since that seems to be a simple fix for your issue.

1 Like

Velocity is a deprecated property. Instead you should be using AssemblyLinearVelocity or alternatively AssemblyAngularVelocity depending on your use case.

I used velocity to simplify but yes, use AssemblyAngularVelocity instead.