Animation stops playing in shift to run script

im sure theres a simple solution to this im justs tupid :sweat_smile:

so my script works as intended but for some reason the run animation doesnt play when i let go of the run key

heres what i mean

heres my code (The client side)

repeat task.wait(1) until game:IsLoaded() task.wait(1)
---------------------
--Services and Localization
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local TS = game:GetService("TweenService")

local IsRunning = player.Backpack.Status.Movement
local IsAttacking = player.Backpack.Status.CanAttack
local stamAmount = player.Backpack.MovementValues.StaminaValue
----------------
local char = player.Character
local head = char.Head
local event = game.ReplicatedStorage.MoveEvent
-----------
local startup
local runEnded
local runAnim = player.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations.Movement.RunAnim)
----------
UIS.InputBegan:Connect(function(input, chat)
	if chat or stamAmount.Value <= 1 or IsRunning.Value == true or IsAttacking.Value == true then return end
	
	if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and input.KeyCode == Enum.KeyCode.W then
		local isKeyCown = UIS:IsKeyDown(Enum.KeyCode.LeftShift)
		local tween = TS:Create(camera, TweenInfo.new(.5), {FieldOfView = 90})
		runAnim:Play()
		tween:Play()
		while UIS:IsKeyDown(Enum.KeyCode.LeftShift) == true do
			if stamAmount.Value >= 1 then
				startup = event:InvokeServer({"Running", isKeyCown})
			end
			if IsAttacking.Value == true then
				break
			end
			task.wait(.05)
		end
	end
end)

UIS.InputEnded:Connect(function(input, chat)
	if chat then return end
	
	if input.KeyCode == Enum.KeyCode.LeftShift  and not UIS:IsKeyDown(Enum.KeyCode.LeftShift) or input.KeyCode == Enum.KeyCode.W then
		runAnim:Stop()
		if startup == true then
			while not UIS:IsKeyDown(Enum.KeyCode.LeftShift) do
				runEnded = event:InvokeServer({"Not Running"})
				if runEnded	== true then
					local tween = TS:Create(camera, TweenInfo.new(.5), {FieldOfView = 70})
					tween:Play()
				end
				task.wait(4)
			end
		end
	end
end)

help and feedback would be greatly appreciated! thank you for your time.

PS: Animation wasnt made by me it was made by @Shonny_Yeet

1 Like