function ControlModule.SelectTouchModule(K)if not UserInputService.TouchEnabled then return nil,false end local D=nil local O=Players.LocalPlayer.DevTouchMovementMode if O==Enum.DevTouchMovementMode.UserChoice then D=movementEnumToModuleMap[UserGameSettings.TouchMovementMode]elseif O==Enum.DevTouchMovementMode.Scriptable then return nil,true else D=movementEnumToModuleMap[O]end return D,true end function ControlModule.OnRenderStepped(D,K)if D.activeController and(D.activeController.enabled and D.humanoid)then local K=D.activeController:GetMoveVector()local O=false if D.vehicleController then K,O=D.vehicleController:Update(K,D.activeControlModule==Gamepad)end D.moveFunction(Players.LocalPlayer,K,D.cameraRelative)D.humanoid.Jump=D.activeController:GetIsJumping()or D.touchJumpController and D.touchJumpController:GetIsJumping()end end function ControlModule.OnHumanoidSeated(O,K,D)if K then if D and D:IsA("\086\101\104\105\099\108\101\083\101\097\116")then if not O.vehicleController then O.vehicleController=O.vehicleController.new(CONTROL_ACTION_PRIORITY)end O.vehicleController:Enable(true,D)end else if O.vehicleController then O.vehicleController:Enable(false,D)end end end function ControlModule.OnCharacterAdded(D,K)D.humanoid=K:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")while not D.humanoid do K.ChildAdded:wait()D.humanoid=K:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")end if D.humanoidSeatedConn then D.humanoidSeatedConn:Disconnect()D.humanoidSeatedConn=nil end D.humanoidSeatedConn=D.humanoid.Seated:Connect(function(K,O)D:OnHumanoidSeated(K,O)end)end function ControlModule.OnCharacterRemoving(D,K)D.humanoid=nil end
-- Choose current Touch control module based on settings (user, dev)
-- Returns module (possibly nil) and success code to differentiate returning nil due to error vs Scriptable
function ControlModule:SelectTouchModule()
	if not UserInputService.TouchEnabled then
		return nil, false
	end
	local touchModule = nil
	local DevMovementMode = Players.LocalPlayer.DevTouchMovementMode
	if DevMovementMode == Enum.DevTouchMovementMode.UserChoice then
		touchModule = movementEnumToModuleMap[UserGameSettings.TouchMovementMode]
	elseif DevMovementMode == Enum.DevTouchMovementMode.Scriptable then
		return nil, true
	else
		touchModule = movementEnumToModuleMap[DevMovementMode]
	end
	return touchModule, true
end

function ControlModule:OnRenderStepped(dt)
	if self.activeController and self.activeController.enabled and self.humanoid then
		local moveVector = self.activeController:GetMoveVector()

		local vehicleConsumedInput = false
		if self.vehicleController then
			moveVector, vehicleConsumedInput =
				self.vehicleController:Update(moveVector, self.activeControlModule == Gamepad)
		end

		-- User of vehicleConsumedInput is commented out to preserve legacy behavior, in case some game relies on Humanoid.MoveDirection still being set while in a VehicleSeat
		--if not vehicleConsumedInput then
		self.moveFunction(Players.LocalPlayer, moveVector, self.cameraRelative)
		--end

		self.humanoid.Jump = self.activeController:GetIsJumping()
			or (self.touchJumpController and self.touchJumpController:GetIsJumping())
	end
end

function ControlModule:OnHumanoidSeated(active, currentSeatPart)
	if active then
		if currentSeatPart and currentSeatPart:IsA("VehicleSeat") then
			if not self.vehicleController then
				self.vehicleController = self.vehicleController.new(CONTROL_ACTION_PRIORITY)
			end
			self.vehicleController:Enable(true, currentSeatPart)
		end
	else
		if self.vehicleController then
			self.vehicleController:Enable(false, currentSeatPart)
		end
	end
end

function ControlModule:OnCharacterAdded(char)
	self.humanoid = char:FindFirstChildOfClass("Humanoid")
	while not self.humanoid do
		char.ChildAdded:wait()
		self.humanoid = char:FindFirstChildOfClass("Humanoid")
	end

	if self.humanoidSeatedConn then
		self.humanoidSeatedConn:Disconnect()
		self.humanoidSeatedConn = nil
	end
	self.humanoidSeatedConn = self.humanoid.Seated:Connect(function(active, currentSeatPart)
		self:OnHumanoidSeated(active, currentSeatPart)
	end)
end

function ControlModule:OnCharacterRemoving(char)
	self.humanoid = nil
end
