Gun run script for fps game

How do I make a run script for a gun like in phantom forces. I need one that I could put my running animation id in it and I have have to press shift WHILE MOVING. And if I’m not moving the animation won’t play if I press shift
Can someone please help me out

What?

You want the player to only be able to toggle sprint while moving?

-- configuration
local useLeftControl = false -- whether the player uses CTRL (left) to toggle shirt


-- other stuff
local get = game.GetService
local uip = get(game, 'UserInputService')
local key = (useLeftControl and Enum.KeyCode.LeftControl) or Enum.KeyCode.LeftShift

function ToggleShift(isSprinting)
	local humanoid; pcall(function()
		humanoid = game.Players.LocalPlayer.Character.Humanoid -- im lazy bro let it slide :()
	end)
	if humanoid then
		local isMoving = humanoid.MoveDirection.magnitude > 0
		if isSprinting then
			if isMoving then
				-- do thing
			end
		else
			-- stop doing thing
		end
	end
end

function doitBro(moment, input, processed)
	if (not processed) and input.KeyCode == key then
		ToggleShift(moment)
	end
end

function ConstructDoItBro(f)
	return function(...)
		doitBro(f, ...)
	end
end

uip.InputBegan:connect(ConstructDoItBro(true))
uip.InputEnded:connect(ConstructDoItBro(false))

This may not be the best, or it may not even work. You write the rest and fix it. Come to me if you need help.