Why does my fall damage script destroy my legs when I have fallen 2 feet?

local bonebreakSoundId = "rbxassetid://3330223037"
local fallDamageSoundId = "rbxassetid://321709239"

local crippled = script.Parent.Crippled


--HERE-------------------------------------
fallTime = 0
while true do
	x = wait()
	if script.Parent.Torso.Velocity.Y <= -10 then --Finds whether or not the player has begun falling and starts a timer
		fallTime = fallTime + x
	end
	local stateType = script.Parent.Humanoid:GetState()
	if stateType ~= Enum.HumanoidStateType.Freefall then
		if fallTime >= 0.4 then --Finds whether or not the player has been falling long enough to take damage
			script.Parent.Humanoid:TakeDamage(math.floor(fallTime * 50)) --Deals damage directly proportional to falling time; can simply change the 50 to another factor balance it differently



--TO HERE-------------------------------------------



			--play sound
			local sound = Instance.new("Sound")
			sound.PlayOnRemove = true

			if math.floor(fallTime * 50) >= 30 and crippled.Value == false then
				sound.SoundId = bonebreakSoundId
				sound.Volume = 2
				script.Parent.Humanoid.Animator:Destroy()
				Instance.new("Animator", script.Parent.Humanoid)
				script.Parent.Animate.walk.WalkAnim.AnimationId = "rbxassetid://10696079614"
				script.Parent.Animate.idle.Animation1.AnimationId = "rbxassetid://10696125730"
				script.Parent.Animate.idle.Animation2.AnimationId = "rbxassetid://10696125730"
				script.Parent.Humanoid.WalkSpeed = 5
				script.Parent.Humanoid.JumpHeight = 0
				crippled.Value = true


				--add crippled legs (had to use collision groups to prevent legs from clipping into broken legs and being jank lol)
				function addLeg(leg, vector)
					local newLeg = game.ServerStorage.brokenLeg:Clone()
					newLeg.CFrame = leg.CFrame
					local attachment = Instance.new("Attachment")
					attachment.Parent = script.Parent.Torso
					attachment.Position = vector
					newLeg.BallSocketConstraint.Attachment1 = attachment
					newLeg.Parent = script.Parent
					script.Parent:FindFirstChild(leg.Name).Transparency = 1
				end
				addLeg(script.Parent["Left Leg"], Vector3.new(-.5, -1, 0))
				addLeg(script.Parent["Right Leg"], Vector3.new(.5, -1, 0))

				--also disable melee if you have to in the future
			else
				sound.Volume = 1
				sound.SoundId = fallDamageSoundId
			end

			sound.Parent = script.Parent.Torso
			sound:Destroy()




			--cripple briefly if damage taken was greater than 30 but less than 50 (50 will break your legs)
			coroutine.wrap(function()
				if crippled.Value == false then
					local walkspeed = script.Parent.Humanoid.WalkSpeed
					script.Parent.Humanoid.WalkSpeed = 11
					wait(1)
					script.Parent.Humanoid.WalkSpeed = walkspeed
				end
			end)()
			print("asdf")

		end
		fallTime = 0
	end
end

Here’s the entire script, but I highlighted (the “here” and “to here” thing lol) the part that I think is likely most important?
That and maybe the bottom of it too

But basically, this script works, but it also damages me randomly if I’m just… jumping. Like, I’ll just be jumping around, and randomly get hurt. One time it somehow dealt 30 damage, meaning it thought I was falling for .6 seconds, which I don’t think I did at all…

My only idea is that by holding jump down, and constantly jumping, it sometimes gets confused and doesn’t reset your fall time to zero when you stop jumping? And so it just adds more on and thinks you fell longer than you did and hurts you?

If that’s the case, or if it’s a separate issue, either way, help?