Need help for my Xbox Sprinting Script

I am coding a sprinting mechanic for Xbox but having troubles and it isn’t working and cannot figure it out.

local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild('Humanoid')

--Editable--
local ID = 10862419793  --Your animation ID!--
local RunningSpeed = 24 --Running speed--
local NormalSpeed = 16  --Normal speed/walkspeed--
local FieldOfView = 80 --Field of view when running--
local key = "Thumbstick1"  --Sprint/Run key--

--Animation--
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = "rbxassetid://13073609250"
RAnimation = Humanoid:LoadAnimation(RunAnimation)
Running = false

--FieldOfView--
local mouse = Player:GetMouse()
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local Properties = {FieldOfView = FieldOfView}
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info, Properties)
local rProperties = {FieldOfView = 70}
local rInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local rT = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, rInfo, rProperties)

--Keypress function--
function Handler(BindName, InputState)
	if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then
		Running = true
		Humanoid.WalkSpeed = RunningSpeed
		T:Play()
	elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then
		Running = false
		if RAnimation.IsPlaying then
			RAnimation:Stop()
		end
		Humanoid.WalkSpeed = NormalSpeed
		rT:Play()
	end
end

--Running with animation and field of view--
Humanoid.Running:connect(function(Speed)
	if Speed >= 10 and Running and not RAnimation.IsPlaying then
		RAnimation:Play()
		Humanoid.WalkSpeed = RunningSpeed
		T:Play()
	elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = NormalSpeed
		rT:Play()
	elseif Speed < 10 and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = NormalSpeed
		rT:Play()
	end
end)

game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode[key])

--Stop animation if...--
Humanoid.Changed:connect(function()
	if Humanoid.Jump and RAnimation.IsPlaying then
		RAnimation:Stop()
	end
end)

Could you format your code using ``` before and after it? Also, what exactly isn’t working? Animations or speedup?

Also, I think the issue you have is here:

KeyCode refers to keyboard, so you’ll need to change to the correct gamepad input instead.

It’s not just that but the entire code is in keyboard type. I just need to re-code everything.

The problem is it isn’t working when using executing button.

I don’t think so. Also, I was wrong regarding the Keycode thing. Certain controller inputs work there, such as Thumbstick1. I’m not sure, but it feels to me as if studio just doesn’t recognize gamepad inputs. Have you tried testing in-game rather than studio?

When I tested in studio it couldn’t detect any controller input.