Cannot figure out a logical way to make an animation specifically for walking

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Cam = workspace.CurrentCamera
local Anim = game.ReplicatedStorage.Animation["Sword pull"]
i = 0
UserInputService.InputBegan:Connect(function(input)
print("played Pressed Key")
if input.KeyCode == Enum.KeyCode.LeftShift then
	player.Character.Humanoid.WalkSpeed = 30
	Cam.FieldOfView = 77
		end
end)
UserInputService.InputEnded:Connect(function(input2)
if input2.KeyCode == Enum.KeyCode.LeftShift then
	player.Character.Humanoid.WalkSpeed = 16
	Cam.FieldOfView = 70
		end
end)
UserInputService.InputBegan:Connect(function(input3)
animload = player.Character.Humanoid:LoadAnimation(Anim)
animload.Priority = Enum.AnimationPriority.Action
if input3.KeyCode == Enum.KeyCode.W then
	while wait() do
		if i == 0 then
			i = 1
			animload:Play()
			wait(animload.Length)
			i = 0
		else 
			animload:AdjustSpeed(1)
		end
	end	
end
UserInputService.InputEnded:Connect(function(input4)
	if input4.KeyCode == Enum.KeyCode.W then
		animload:AdjustSpeed(0)
	end
end)
end)

Cannot for the life of me figure out a way to make this work as I need it to, I can’t stop the animation because it cannot reference my character if it is at the beginning and it also cannot reference the animation to stop it if it’s contained within the if-then statement.

Forking the default Animate script is the easiest way to do this. If you don’t know how, look it up on this forum and you will probably find your solution pretty quickly.

Load the animation track once, outside of an event binding. You’re loading a separate new AnimationTrack with animload = player.Character.Humanoid:LoadAnimation(Anim)

The old animload doesn’t stop playing by overwriting it’s reference.

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Cam = workspace.CurrentCamera
local Anim = game.ReplicatedStorage.Animation["Sword pull"]
if not player.Character then
    player.CharacterAdded:Wait()
end
local animload = player.Character.Humanoid:LoadAnimation(Anim)

You also have 2 copies of the user input events. You only need to bind to InputBegan & InputChanged once, then use an if keycode elseif other keycode end conditional chain to filter the logic.