Jump Fatigue Not Working As Intended

Hi, scripter named @overflowed helped me create a Jump Fatigue script.

it’s a little off, and I don’t know how to fix it. In the script the “JumpFatigueTime” starts right when Jump Fatigue is applied.

I am trying to have it so the “JumpFatigueTime” starts after the player stops jumping in a 1-second time period, like this:

Here is the current script:

---game/StarterPlayer/StarterCharacterScripts/Fatigue.client.lua

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid: Humanoid = Character:WaitForChild("Humanoid")

local Settings = {
	JumpPower = 50; --How high the player character jumps initially.
	JumpFatigueScalar = 0.5; --How much percent the jump power is reduced when the player is fatigued.
	JumpFatigueTime = 1; --How long the player has to wait after a fatigued jump before their jump power returns to normal.
	JumpLenience = 2; --The number of jumps a character can perform before fatigue affects them.
	JumpLenienceReset = 1; -- How often the jump count resets, allowing the player to jump without fatigue.
}

local FatigueStart = 0
local LastNonFatigueJump = 0
local CurrentLenience = Settings.JumpLenience

local function Lerp(v0: number, v1: number, a: number): number
	return (1 - a) * v0 + a * v1
end

local function OnNonFatigueJump()
	local Now = os.clock()

	if Now - LastNonFatigueJump > Settings.JumpLenienceReset then
		CurrentLenience = Settings.JumpLenience
	end

	LastNonFatigueJump = Now
	CurrentLenience -= 1

	if CurrentLenience == 0 then
		FatigueStart = Now
	end
end

local function IsJumpFatigued(): (boolean, number)
	local delta = os.clock() - FatigueStart
	return delta < Settings.JumpFatigueTime, 1 - (delta / Settings.JumpFatigueTime)
end

local function StateChanged(_, New: Enum.HumanoidStateType)
	if New ~= Enum.HumanoidStateType.Jumping then return end

	local IsFatigued, Gradient = IsJumpFatigued()
	if IsFatigued then
			Humanoid.JumpPower = Lerp(Settings.JumpPower * Settings.JumpFatigueScalar, Settings.JumpPower, Gradient)
		CurrentLenience = Settings.JumpLenience
	else
		Humanoid.JumpPower = Settings.JumpPower
		OnNonFatigueJump()
	end

	print(Humanoid.JumpPower)
end

Humanoid.StateChanged:Connect(StateChanged)