When I press any key my character stops running

Basically I have a script to run, in which when I press shift the character runs, but when I press any key either a or control it continues the running animation, but has the walking speed


This is the code

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local run = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Movement"):WaitForChild("Run")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(run)
local BackRunning = player.PlayerScripts:WaitForChild("Values"):WaitForChild("BackRunning")
local IsAttacking = player.PlayerScripts:WaitForChild("Values"):WaitForChild("IsAttacking")
local IsDashing = player.PlayerScripts:WaitForChild("Values"):WaitForChild("IsDashing")
local isrunning = player.PlayerScripts:WaitForChild("Values"):WaitForChild("IsRunning")

--[[humanoid.StateChanged:Connect(function(_, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		-- Detener la animación de correr y reproducir la animación de saltar
		animationTrack:Stop()
	elseif newState == Enum.HumanoidStateType.Freefall then
		-- Reanudar la animación de correr cuando el personaje aterrice
		task.wait(0.5)
		if Character.HumanoidRootPart.Position.Y < 5 and isrunning.Value then
			animationTrack:Play()
			humanoid.WalkSpeed = 21
		end
	end
end)
]]
--run again
--[[BackRunning.Changed:Connect(function(value)
	if value == true then
		animationTrack:Play()
		humanoid.WalkSpeed = 21
		BackRunning.Value = false
	end
end)
]]

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then
		return
	end
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			local IsBlocking = Character:GetAttribute("IsBlocking")
			local IsStuning = Character:GetAttribute("IsStuning")
			if IsAttacking.Value or IsBlocking or IsStuning then
				return
			end
			if humanoid.MoveDirection.Magnitude > 0 then
				isrunning.Value = true
				humanoid.WalkSpeed = 21
				animationTrack:Play()
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then
		return
	end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		local IsBlocking = Character:GetAttribute("IsBlocking")
		if IsAttacking.Value or IsBlocking == true then
			return
		end
		print("a")
		humanoid.WalkSpeed = 10
		animationTrack:Stop()
		isrunning.Value = false
	end
end)
--[[
game:GetService("RunService").Heartbeat:Connect(function()
	if IsDashing.Value and humanoid.MoveDirection.Magnitude > 0 and isrunning.Value then
		animationTrack:Stop()
	end
	local KatanaEquipped = Character:GetAttribute("KatanaEquipped")
	local KatanaUnequipped = Character:GetAttribute("KatanaUnequipped")
	if KatanaEquipped or KatanaUnequipped then
		animationTrack:Stop()
		humanoid.WalkSpeed = 10
	end
	local IsBlocking = Character:GetAttribute("IsBlocking")
	if IsBlocking then
		animationTrack:Stop()
	end
	if humanoid.MoveDirection.Magnitude <= 0 and isrunning.Value then
		humanoid.WalkSpeed = 10
		animationTrack:Stop()
	end
	if isrunning.Value and humanoid:GetState() == Enum.HumanoidStateType.Freefall then
		if Character.HumanoidRootPart.Position.Y > 7 then
			animationTrack:Stop()
			humanoid.WalkSpeed = 10
		end
	end
end)
]]

Try ending the “InputBegan” function if “isrunning” is true. It could be because of the event firing twice

mhhh, try with

if uis:IsKeyDown(Enum.KeyCode.LeftShift) then

it detects if a key in holded, not pressed