How to detect when a player has fell a certain amount of studs Mid-Air?

Hello! i was wondering how would i make it so a script can detect when a a player falls a certain amount of studs Mid-Air?

This is the script i use:

local char = script.Parent
local root = char:WaitForChild(“HumanoidRootPart”)
local humanoid = char:WaitForChild(“Humanoid”)

	if humanoid and root then
		
		local headHeight
		
		humanoid.FreeFalling:Connect(function (state)
			if state then
				headHeight = root.Position.Y
			elseif not state and headHeight ~= nil then
			pcall(function ()

					local fell = headHeight - root.Position.Y

					if fell >= 40 then
				script.Parent.Ragdolled.Value=true
					end
				end)
			end
		end)
	end

But this script only detects it when the player hits the ground, any solutions?

1 Like

Just use Humanoid.StateChanged to check if the player just started falling and when it’s landed.

1 Like
Humanoid.StateChanged:Connect(function(PreviousState, NewState)
	if NewState == Enum.HumanoidStateType.Freefall then
		-- what to do when it starts falling
	elseif NewState == Enum.HumanoidStateType.Landed then
		-- what to do when it landed
	end
end
3 Likes

You can use velocity to find the speed at which someone is falling (id use this)

I found an article on this topic but not sure if it’s works I’m on my phone: https://scriptinghelpers.org/questions/248/how-would-i-create-fall-damage-in-my-game

local falling = HumanoidRootPart.Velocity.Y

Or just when they start falling get their position store it in a variable wait a second then get their position again and if it’s how ever many studs different in the Y axis then you can enable your damage

Roblox gravity by default I believe is 196 studs/s
Basically
H = Height (what you want)
G = Gravity (9.8)
T = Time from falling to landed

h=1/2gt^2

8 Likes