Help with custom fall damage system

	if prot then
		if prot == 0.1 then
			humanoid.Parent.Shield.Health.Value -= damage/1.3
		else
			humanoid.Health -= (damage*prot)
		end
	else
		humanoid.Health -= damage
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		task.wait(3)
		while task.wait(0.1) do
			local humPart = char:FindFirstChild("HumanoidRootPart")
			local humanoid = char:FindFirstChild("Humanoid")
			if humPart and humanoid then
				warn("--------------------------------")
				warn(humPart.Velocity.Y)
				if humPart.Velocity.Y <= -60 then
					while task.wait(0.1) do
						warn("inloop")
						local rayParams = RaycastParams.new()
						rayParams.FilterDescendantsInstances = {char}
						local raycastResult = workspace:Raycast(humPart.Position,humPart.Position + Vector3.new(0,-7,0),rayParams)
						if raycastResult then break end
					end
					humanoid:TakeDamage(25)
				end
			end
		end
	end)
end)

So far, it works super well when you’re jumping off of a high spot in the lower part of the map in my game, but when you go to this certain top part, it just gets stuck in its while loop continuously warning, “inloop” although I am on land and the raycast should be working fine.

The reason why this is custom instead of a .FreeFalling thing is because it needs to be compatable with ragdolling.

Instead of checking the RootParts Velocity, you could try checking the Humanoid State Type.

if humanoid:GetState() == Enum.HumanoidStateType.Freefall then

end

Im not sure if this will work with ragdolls though, as i dont use them.

I think it would be more appropriate to connect to Humanoid.StateChanged and wait for the character to land. That would look something like this.

humanoid.StateChanged:Connect(function (oldState, newState)
	if newState ~= Enum.HumanoidStateType.Landed then return end
	
	local d = 100 + humanoid.RootPart.AssemblyLinearVelocity.Y
	
	if 0 <= d then return end
	
	print(string.format("Taking %.2f damage!", d))
	
	humanoid:TakeDamage(-d)
end)

Guys, I literally said rag dolling doesn’t work with the humanoid falling -_-