local Y=require(script.Parent:WaitForChild("\066\097\115\101\067\104\097\114\097\099\116\101\114\067\111\110\116\114\111\108\108\101\114"))local w=setmetatable({},Y)w.__index=w local s,M=pcall(function()return(UserSettings()):IsUserFeatureEnabled("\085\115\101\114\080\108\097\121\101\114\083\099\114\105\112\116\115\066\105\110\100\065\116\080\114\105\111\114\105\116\121")end)local x=s and M function w.new(s)local M=setmetatable(Y.new(),w)M.CONTROL_ACTION_PRIORITY=s M.forwardValue=0 M.backwardValue=0 M.leftValue=0 M.rightValue=0 M.activeGamepad=NONE M.gamepadConnectedConn=nil M.gamepadDisconnectedConn=nil return M end function w.Enable(w,Y)if not UserInputService.GamepadEnabled then return false end if Y==w.enabled then return true end w.forwardValue=0 w.backwardValue=0 w.leftValue=0 w.rightValue=0 w.moveVector=ZERO_VECTOR3 w.isJumping=false if Y then w.activeGamepad=w:GetHighestPriorityGamepad()if w.activeGamepad~=NONE then w:BindContextActions()w:ConnectGamepadConnectionListeners()else return false end else w:UnbindContextActions()w:DisconnectGamepadConnectionListeners()w.activeGamepad=NONE end w.enabled=Y return true end
--[[ The Module ]]
--
local BaseCharacterController = require(script.Parent:WaitForChild("BaseCharacterController"))
local Gamepad = setmetatable({}, BaseCharacterController)
Gamepad.__index = Gamepad

local bindAtPriorityFlagExists, bindAtPriorityFlagEnabled = pcall(function()
	return UserSettings():IsUserFeatureEnabled("UserPlayerScriptsBindAtPriority")
end)
local FFlagPlayerScriptsBindAtPriority = bindAtPriorityFlagExists and bindAtPriorityFlagEnabled

function Gamepad.new(CONTROL_ACTION_PRIORITY)
	local self = setmetatable(BaseCharacterController.new(), Gamepad)

	self.CONTROL_ACTION_PRIORITY = CONTROL_ACTION_PRIORITY

	self.forwardValue = 0
	self.backwardValue = 0
	self.leftValue = 0
	self.rightValue = 0

	self.activeGamepad = NONE -- Enum.UserInputType.Gamepad1, 2, 3...
	self.gamepadConnectedConn = nil
	self.gamepadDisconnectedConn = nil
	return self
end

function Gamepad:Enable(enable)
	if not UserInputService.GamepadEnabled then
		return false
	end

	if enable == self.enabled then
		-- Module is already in the state being requested. True is returned here since the module will be in the state
		-- expected by the code that follows the Enable() call. This makes more sense than returning false to indicate
		-- no action was necessary. False indicates failure to be in requested/expected state.
		return true
	end

	self.forwardValue = 0
	self.backwardValue = 0
	self.leftValue = 0
	self.rightValue = 0
	self.moveVector = ZERO_VECTOR3
	self.isJumping = false

	if enable then
		self.activeGamepad = self:GetHighestPriorityGamepad()
		if self.activeGamepad ~= NONE then
			self:BindContextActions()
			self:ConnectGamepadConnectionListeners()
		else
			-- No connected gamepads, failure to enable
			return false
		end
	else
		self:UnbindContextActions()
		self:DisconnectGamepadConnectionListeners()
		self.activeGamepad = NONE
	end

	self.enabled = enable
	return true
end
