function Gamepad.Enable(n)local R=0 local Y=0 local z=0 local d=0 local l=LocalPlayer.Move local r=UserInputService.GamepadSupports local y=function(n,R,Y)if Y.UserInputType~=Enum.UserInputType.Gamepad1 then return end if Y.KeyCode~=Enum.KeyCode.Thumbstick1 then return end if hasCancelType and R==Enum.UserInputState.Cancel then MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)return end if Y.Position.magnitude>thumbstickDeadzone then MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(Y.Position.X,0,-Y.Position.Y)MasterControl:AddToPlayerMovement(currentMoveVector)else MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)end end local E=function(n,R,Y)if Y.UserInputType~=Enum.UserInputType.Gamepad1 then return end if Y.KeyCode~=Enum.KeyCode.ButtonA then return end if hasCancelType and R==Enum.UserInputState.Cancel then MasterControl:SetIsJumping(false)return end MasterControl:SetIsJumping(Y.UserInputState==Enum.UserInputState.Begin)end local T=function()if not r(UserInputService,Enum.UserInputType.Gamepad1,Enum.KeyCode.Thumbstick1)then if LocalPlayer and LocalPlayer.Character then MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(z+d,0,R+Y)MasterControl:AddToPlayerMovement(currentMoveVector)end end end local g=function(n,Y,z)if Y==Enum.UserInputState.End then R=-1 elseif Y==Enum.UserInputState.Begin or hasCancelType and Y==Enum.UserInputState.Cancel then R=0 end T()end local L=function(n,R,z)if R==Enum.UserInputState.End then Y=1 elseif R==Enum.UserInputState.Begin or hasCancelType and R==Enum.UserInputState.Cancel then Y=0 end T()end local j=function(n,R,Y)if R==Enum.UserInputState.End then z=-1 elseif R==Enum.UserInputState.Begin or hasCancelType and R==Enum.UserInputState.Cancel then z=0 end T()end local C=function(n,R,Y)if R==Enum.UserInputState.End then d=1 elseif R==Enum.UserInputState.Begin or hasCancelType and R==Enum.UserInputState.Cancel then d=0 end T()end ContextActionService:BindAction("\074\117\109\112\066\117\116\116\111\110",E,false,Enum.KeyCode.ButtonA)ContextActionService:BindAction("\077\111\118\101\084\104\117\109\098\115\116\105\099\107",y,false,Enum.KeyCode.Thumbstick1)ContextActionService:BindAction("\102\111\114\119\097\114\100\068\112\097\100",g,false,Enum.KeyCode.DPadUp)ContextActionService:BindAction("\098\097\099\107\119\097\114\100\068\112\097\100",L,false,Enum.KeyCode.DPadDown)ContextActionService:BindAction("\108\101\102\116\068\112\097\100",j,false,Enum.KeyCode.DPadLeft)ContextActionService:BindAction("\114\105\103\104\116\068\112\097\100",C,false,Enum.KeyCode.DPadRight)ContextActionService:BindActivate(Enum.UserInputType.Gamepad1,Enum.KeyCode.ButtonR2)UserInputService.GamepadDisconnected:connect(function(n)if n~=Enum.UserInputType.Gamepad1 then return end MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)end)UserInputService.GamepadConnected:connect(function(n)if n~=Enum.UserInputType.Gamepad1 then return end MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)end)end function Gamepad.Disable(n)ContextActionService:UnbindAction("\102\111\114\119\097\114\100\068\112\097\100")ContextActionService:UnbindAction("\098\097\099\107\119\097\114\100\068\112\097\100")ContextActionService:UnbindAction("\108\101\102\116\068\112\097\100")ContextActionService:UnbindAction("\114\105\103\104\116\068\112\097\100")ContextActionService:UnbindAction("\077\111\118\101\084\104\117\109\098\115\116\105\099\107")ContextActionService:UnbindAction("\074\117\109\112\066\117\116\116\111\110")ContextActionService:UnbindActivate(Enum.UserInputType.Gamepad1,Enum.KeyCode.ButtonR2)MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)MasterControl:SetIsJumping(false)end return Gamepad
--
function Gamepad:Enable()
	local forwardValue  = 0
	local backwardValue = 0
	local leftValue = 0
	local rightValue = 0
	
	local moveFunc = LocalPlayer.Move
	local gamepadSupports = UserInputService.GamepadSupports
	
	local controlCharacterGamepad1 = function(actionName, inputState, inputObject)
		if inputObject.UserInputType ~= Enum.UserInputType.Gamepad1 then return end
		if inputObject.KeyCode ~= Enum.KeyCode.Thumbstick1 then return end
		
		if hasCancelType and inputState == Enum.UserInputState.Cancel then
			MasterControl:AddToPlayerMovement(-currentMoveVector)
			currentMoveVector =  Vector3.new(0,0,0)
			return
		end
		
		if inputObject.Position.magnitude > thumbstickDeadzone then
			MasterControl:AddToPlayerMovement(-currentMoveVector)
			currentMoveVector =  Vector3.new(inputObject.Position.X, 0, -inputObject.Position.Y)
			MasterControl:AddToPlayerMovement(currentMoveVector)
		else
			MasterControl:AddToPlayerMovement(-currentMoveVector)
			currentMoveVector =  Vector3.new(0,0,0)
		end
	end
	
	local jumpCharacterGamepad1 = function(actionName, inputState, inputObject)		
		if inputObject.UserInputType ~= Enum.UserInputType.Gamepad1 then return end
		if inputObject.KeyCode ~= Enum.KeyCode.ButtonA then return end
		
		if hasCancelType and inputState == Enum.UserInputState.Cancel then
			MasterControl:SetIsJumping(false)
			return
		end
		
		MasterControl:SetIsJumping(inputObject.UserInputState == Enum.UserInputState.Begin)
	end
	
	local doDpadMoveUpdate = function()
		if not gamepadSupports(UserInputService, Enum.UserInputType.Gamepad1, Enum.KeyCode.Thumbstick1) then
			if LocalPlayer and LocalPlayer.Character then
				MasterControl:AddToPlayerMovement(-currentMoveVector)
				currentMoveVector = Vector3.new(leftValue + rightValue,0,forwardValue + backwardValue)
				MasterControl:AddToPlayerMovement(currentMoveVector)
			end
		end
	end
	
	local moveForwardFunc = function(actionName, inputState, inputObject)
		if inputState == Enum.UserInputState.End then
			forwardValue = -1
		elseif inputState == Enum.UserInputState.Begin or (hasCancelType and inputState == Enum.UserInputState.Cancel) then
			forwardValue = 0
		end
		
		doDpadMoveUpdate()
	end
	
	local moveBackwardFunc = function(actionName, inputState, inputObject)	
		if inputState == Enum.UserInputState.End then
			backwardValue = 1
		elseif inputState == Enum.UserInputState.Begin or (hasCancelType and inputState == Enum.UserInputState.Cancel) then
			backwardValue = 0
		end
		
		doDpadMoveUpdate()
	end
	
	local moveLeftFunc = function(actionName, inputState, inputObject)	
		if inputState == Enum.UserInputState.End then
			leftValue = -1
		elseif inputState == Enum.UserInputState.Begin or (hasCancelType and inputState == Enum.UserInputState.Cancel) then
			leftValue = 0
		end
		
		doDpadMoveUpdate()
	end
	
	local moveRightFunc = function(actionName, inputState, inputObject)	
		if inputState == Enum.UserInputState.End then
			rightValue = 1
		elseif inputState == Enum.UserInputState.Begin or (hasCancelType and inputState == Enum.UserInputState.Cancel) then
			rightValue = 0
		end
		
		doDpadMoveUpdate()
	end
	
	ContextActionService:BindAction("JumpButton",jumpCharacterGamepad1, false, Enum.KeyCode.ButtonA)
	ContextActionService:BindAction("MoveThumbstick",controlCharacterGamepad1, false, Enum.KeyCode.Thumbstick1)
	
	ContextActionService:BindAction("forwardDpad", moveForwardFunc, false, Enum.KeyCode.DPadUp)
	ContextActionService:BindAction("backwardDpad", moveBackwardFunc, false, Enum.KeyCode.DPadDown)
	ContextActionService:BindAction("leftDpad", moveLeftFunc, false, Enum.KeyCode.DPadLeft)
	ContextActionService:BindAction("rightDpad", moveRightFunc, false, Enum.KeyCode.DPadRight)
	
	ContextActionService:BindActivate(Enum.UserInputType.Gamepad1, Enum.KeyCode.ButtonR2)
	
	
	UserInputService.GamepadDisconnected:connect(function(gamepadEnum)
		if gamepadEnum ~= Enum.UserInputType.Gamepad1 then return end
		
		MasterControl:AddToPlayerMovement(-currentMoveVector)
		currentMoveVector = Vector3.new(0,0,0)
	end)

	UserInputService.GamepadConnected:connect(function(gamepadEnum)
		if gamepadEnum ~= Enum.UserInputType.Gamepad1 then return end
		
		MasterControl:AddToPlayerMovement(-currentMoveVector)
		currentMoveVector = Vector3.new(0,0,0)
	end)
end

function Gamepad:Disable()
	
	ContextActionService:UnbindAction("forwardDpad")
	ContextActionService:UnbindAction("backwardDpad")
	ContextActionService:UnbindAction("leftDpad")
	ContextActionService:UnbindAction("rightDpad")
	
	ContextActionService:UnbindAction("MoveThumbstick")
	ContextActionService:UnbindAction("JumpButton")
	ContextActionService:UnbindActivate(Enum.UserInputType.Gamepad1, Enum.KeyCode.ButtonR2)
	
	MasterControl:AddToPlayerMovement(-currentMoveVector)
	currentMoveVector = Vector3.new(0,0,0)
	MasterControl:SetIsJumping(false)
end

return Gamepad
