The front flip bug after backflip or backflip1

Hi,

  1. I want the front flip to work properly after performing a backflip, backflip1, and after pressing Ctrl without any bugs.

  2. The issue occurs when the player performs a backflip (Ctrl + Jump) or backflip1. If the player then attempts a front flip (double-tap jump), they only need to press jump once to execute a front flip. This problem only happens after backflips or if the player presses Ctrl without interacting with the flip parts.

  3. The solution I tried was to reset SpaceCount to 0 after backflips:

-- Character.HumanoidRootPart.Touched:Connect(function(hit)
if hit.Name == "FrontFlipPart" then
SpaceCount = 0
TouchingFrontFlipPart = true
elseif hit.Name == "BackFlipPart" then
SpaceCount = 0
TouchingBackFlipPart = true
elseif hit.Name == "BackFlipPart1" then
SpaceCount = 0
TouchingBackFlipPart1 = true
end
end)

Character.HumanoidRootPart.TouchEnded:Connect(function(hit)
if hit.Name == "FrontFlipPart" then
SpaceCount = 0
TouchingFrontFlipPart = false
elseif hit.Name == "BackFlipPart" then
SpaceCount = 0
TouchingBackFlipPart = false
elseif hit.Name == "BackFlipPart1" then
SpaceCount = 0
TouchingBackFlipPart1 = false
end
end)

— However, this did not work, and the same issue still occurs.

-- Character.HumanoidRootPart.Touched:Connect(function(hit)
if hit.Name == "FrontFlipPart" then
SpaceCount = 0
TouchingFrontFlipPart = true
elseif hit.Name == "BackFlipPart" then
SpaceCount = 0
TouchingBackFlipPart = true
elseif hit.Name == "BackFlipPart1" then
SpaceCount = 0
TouchingBackFlipPart1 = true
end
end)

Character.HumanoidRootPart.TouchEnded:Connect(function(hit)
if hit.Name == "FrontFlipPart" then
SpaceCount = 0
TouchingFrontFlipPart = false
elseif hit.Name == "BackFlipPart" then
SpaceCount = 0
TouchingBackFlipPart = false
elseif hit.Name == "BackFlipPart1" then
SpaceCount = 0
TouchingBackFlipPart1 = false
end
end)

local function Jump()
print("Jump triggered. SpaceCount:", SpaceCount)

if Rolling then
return
end

if TouchingBackFlipPart1 and UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
print("Performing 1BackFlip")
PlayAndStopOtherAnimations(Animations["1BackFlip"])
return
elseif TouchingBackFlipPart and UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
print("Performing BackFlip")
PlayAndStopOtherAnimations(Animations.BackFlip)
return
elseif TouchingFrontFlipPart then
SpaceCount = SpaceCount + 1
print("TouchingFrontFlipPart. SpaceCount:", SpaceCount)
if SpaceCount == 2 then
print("Performing FrontFlip")
PlayAndStopOtherAnimations(Animations.FrontFlip)
SpaceCount = 0
return
end
else
SpaceCount = 0
end

if not Holding then
return
end

Holding = false

Animations.Hold:Stop()

PlayAndStopOtherAnimations(Animations.Climb)

wait(0.1)

Character.HumanoidRootPart.Anchored = false

local BodyVelocity = Instance.new("BodyVelocity", Character.HumanoidRootPart)
BodyVelocity.MaxForce = Vector3.new(1,1,1) * math.huge
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 5 + Vector3.new(0, 7, 0)

Animations.Climb.Stopped:Wait()

BodyVelocity:Destroy()

Idling = true
Humanoid.AutoRotate = true
end

as you can see first time i do the frontflip i double tap jump to frontflips but after i click ctrl or do backflips i only have to press jump once to frontflip.

Any help is appreciated. Thank you.