Problems with "jump suspension"

I’ve been trying to create “jump suspension,” basically simulating the player bending their knees after a landing a jump. I am using a sine wave and setting the y value of the sine wave to CameraOffset property of the humanoid to accomplish this. Although, the “jump suspension” sometimes works and sometimes doesn’t.

Code:

local players = game:GetService("Players")
local runService = game:GetService("RunService")

local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local landed = false
local elapsed = 0

humanoid.StateChanged:Connect(function(old, new)
	if old == Enum.HumanoidStateType.Freefall and new == Enum.HumanoidStateType.Landed then
		elapsed = 0
		landed = true
	end
end)

runService:BindToRenderStep("Camera", 200, function(dt)
	if landed then
		elapsed += dt
		
		local y = -math.abs(1 * math.sin(elapsed * 6))
		humanoid.CameraOffset = Vector3.new(0, y, 0)
		
		if y >= -0.05 then
			landed = false
		end
	end
end)

Video: