Need help fixing my fall damage script

I’m making fall damage for my game currently, and it doesn’t work. It only prints ‘Falling’, I’m not good at making things related to the humanoid. I know what to do, but don’t know how to make it work. Here’s my attempt.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Velocity
		local humanoid = char:WaitForChild("Humanoid")
		local falling = false
		humanoid.StateChanged:Connect(function(oldState,newState)
			if newState == Enum.HumanoidStateType.Freefall or Enum.HumanoidStateType.FallingDown then
				Velocity = char.Torso.Velocity.Y
				print("Falling")
				end
			    humanoid.StateChanged:Connect(function(oldState,newState)
				if newState == Enum.HumanoidStateType.Freefall then
					falling = true
					while falling do
						wait(.05)
						Velocity = char.HumanoidRootPart.Velocity.Y
					end
				elseif Enum.HumanoidStateType.Landed then
					
					if Velocity >-20 then
					falling = false
				elseif Velocity <-20 then
					humanoid:TakeDamage(Velocity)
					Velocity = 0
					falling = false
					
					end
			end
			end)
			end)
	end)
	end)

A couple questions:

  1. What type of script is it (Local)?
  2. Where the script is in your game (ServerScriptService, StarterPlayerScripts)?
  3. Rig type of the game (R6 or R15)?

Ah I’ve found the issue.

Going upwards is in the positive direction so velocity will be positive. Therefore, falling downwards is in the negative direction so velocity will be negative.

What you’re actually doing is adding a negative to a negative. Taking damage is a negative and the velocity is negative. This means you are adding health to the player. An easy fix is to add a minus here:

humanoid:TakeDamage(-Velocity)

However, that can be a lot of damage taken in one go so I suggest multiplying it by a constant like 0.1 here:

humanoid:TakeDamage(-Velocity * 0.1)