Tiny issue with my running script

Hi,
I’m experiencing a weird problem with my running script where if I were to move and then hold down shift, I can run just fine. But doing it the opposite way (What I meant by that if I hold shift then move instead of moving first) my running script doesn’t work. How can I fix it?

The whole script:

local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

--Player-Related
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Character = Player.Character
local Humanoid = script.Parent:WaitForChild("Humanoid")

local RunningAnimation = Instance.new("Animation")
RunningAnimation.AnimationId = "rbxassetid://9637085813"
RunningTrack = Character.Humanoid:LoadAnimation(RunningAnimation)


local tweenService = game:GetService("TweenService")
local function tweenFov(duration, fov)

	local tween = tweenService:Create(Camera, TweenInfo.new(duration, Enum.EasingStyle.Quad), {FieldOfView = fov})
	tween:Play()

	spawn(function()
		tween.Completed:Wait()
		tween:Destroy()
	end)
end

NormalSpeed = Humanoid.WalkSpeed
RunSpeed = 24
local normalFOV = 70
local RunningFOV = 75


userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift and Humanoid.MoveDirection.Magnitude > 0  then
		replicatedStorage.Sprint:FireServer("Began")
		Humanoid.WalkSpeed = 29
		tweenFov(0.2,RunningFOV)
		RunningTrack:Play()
	end
	
	local function moveDirectionChanged()
		if Humanoid.MoveDirection.Magnitude == 0 then
			tweenFov(0.2,normalFOV)
			Humanoid.WalkSpeed = 15
			RunningTrack:Stop()
		end
	end

	Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(moveDirectionChanged)
end)


userInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		replicatedStorage.Sprint:FireServer("Ended")
		tweenFov(0.2,normalFOV)
		Humanoid.WalkSpeed = 15
		RunningTrack:Stop()
	end
end)

Humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Jumping then
		replicatedStorage.Sprint:FireServer("Ended")
		tweenFov(0.2,normalFOV)
		Humanoid.WalkSpeed = 15
		RunningTrack:Stop()
	end
end)

-- Update with the Stamina GUI
replicatedStorage.StaminaUpdate.OnClientEvent:Connect(function(stamina, maxStamina)
	players.LocalPlayer.PlayerGui.Stamina.Bar.Size = UDim2.new((stamina / maxStamina) * .2, 0, .044, 0)
end)

Is the animation’s priority set to Action or higher?

I put the priority as movement,

Try setting it higher?

It didn’t work, I don’t think the priority is the problem

Try loading the animation onto Humanoid.Animator.

Nope, still didn’t work.
I think I’m missing something in the script that allows me to do bothways