Strange bug with defining console controls

Hi,
Ive currently got a working stamina function and have been trying to make it so that if the game is played on a console, pressing R2/RT will allow the player to sprint. The script is as follows:

-- Sprint Key Pressed
print("it has reached this point")
userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift or Enum.KeyCode.ButtonR2 then
		print("Left Shift Pressed")
		if currentStamina >= staminaCost and character.Humanoid.MoveDirection.Magnitude > 0 and IsAllowed then
			character.Humanoid.WalkSpeed = sprintSpeed
			print("Sprinted")
		end
	end
end)

-- Sprint Key Released
userInputService.InputEnded:Connect(function (input)
	if input.KeyCode == Enum.KeyCode.LeftShift or Enum.KeyCode.ButtonR2 and IsAllowed then
		character.Humanoid.WalkSpeed = walkSpeed
	end
end)

The strange thing is, is when I add the ‘Enum.KeyCode.ButtonR2’ aspect of the code, sprinting works on the console, however EVERY single console button now functions to activate sprinting (e.g. even pressing x or b on xbox makes the player sprint) which is really strange since ive only defined it to R2. Secondly, Having it in allows me to use sprint with spacebar on PC aswell as left shift? Overall when I remove the ButtonR2 aspect on PC the glitch with using spacebar fixes and then on console I can no longer sprint using any button (as expected)

Anyone got an ideas or have experienced this bug themselves?

Putting the console controls in its separate section checking gamepad is enabled fixed this