Help with velocity based fall damage

My friend has written a script to deal fall damage based on how fast the player is falling
when the player walks up and down the slope it deals damage to the player. we have tried using print statements to debug but cant find what’s wrong. he has the script in ServerScriptService right now

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local HRP = Character["HumanoidRootPart"]
		local Humanoid = Character["Humanoid"]
		if HRP == nil or Humanoid == nil then return end
		Thread = coroutine.wrap(function()
			Humanoid.Died:Connect(function()
				coroutine.yield(Thread)
			end)
			while true do
				wait()
				--print(HRP.Velocity.Y)
				if HRP.Velocity.Y < 60 then
					local FallStart = tick()
					local TopVelocity = math.huge
					repeat
						wait()
						if HRP.Velocity.Y < TopVelocity then
							TopVelocity = HRP.Velocity.Y
							--print(TopVelocity)
						end
					until
					HRP.Velocity.Y >= 0
					local FallTime = tick() - FallStart
					if FallTime > 0.6 then
						Humanoid:TakeDamage((10 * FallTime) + (0.25 * -TopVelocity))
						
					end
				end
			end
		end)()
	end)
end)

The first if statement checks when the y velocity is below 60. I’m not too sure if this will fix your problem, but you could try to check if it’s less than -60. I’ve done some testing with the character velocity for one of my projects, and the y velocity goes to the negatives when falling. So if you try

if HRP.Velocity.Y < 60 then
--insert code here.

it should work. Goodluck on your game!