My fall damage script is not breaking trough the loop

My script is not printing anything at all, I passed out crying 3 times already and I cannot find a solution anywhere.

Here is what I have now:

  • The script you told me
  • The changes to the gliding script adapted to the new script
  • This code that made me cry and pass out 3 times (fall damage script):
-- Variables
local damageHeight = 14 -- The height at which the player will start getting damaged at
local lethalHeight = 26 -- The height at which the player will get killed

game:GetService("Players").PlayerAdded:Connect(function (plr)
	plr.CharacterAdded:Connect(function (char)

		local root = char:WaitForChild("HumanoidRootPart")
		local humanoid = char:WaitForChild("Humanoid")

		if humanoid and root then
			local gliding = plr:WaitForChild("Gliding")
			
			if gliding.Value == true then return end
			local headHeight

			wait(3) -- Prevent the player from dying on spawn
			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 >= lethalHeight then
							humanoid.Health = 0
						elseif fell >= damageHeight then
							humanoid.Health = humanoid.Health - math.floor(fell)
						end
					end)
				end
			end)
		end
	end)
end)
  • And my electricity at home keeping on going away