local w=nil if IsTouchDevice then createTouchGuiContainer()w=function()local w=nil local l=false if not IsUserChoice then if DevMovementMode==Enum.DevTouchMovementMode.Thumbstick then w=ControlModules.Thumbstick l=true elseif DevMovementMode==Enum.DevTouchMovementMode.Thumbpad then w=ControlModules.Thumbpad l=true elseif DevMovementMode==Enum.DevTouchMovementMode.DPad then w=ControlModules.DPad elseif DevMovementMode==Enum.DevTouchMovementMode.ClickToMove then w=nil elseif DevMovementMode==Enum.DevTouchMovementMode.Scriptable then w=nil end else if UserMovementMode==Enum.TouchMovementMode.Default or UserMovementMode==Enum.TouchMovementMode.Thumbstick then w=ControlModules.Thumbstick l=true elseif UserMovementMode==Enum.TouchMovementMode.Thumbpad then w=ControlModules.Thumbpad l=true elseif UserMovementMode==Enum.TouchMovementMode.DPad then w=ControlModules.DPad elseif UserMovementMode==Enum.TouchMovementMode.ClickToMove then w=nil end end setClickToMove()if w~=CurrentControlModule then if CurrentControlModule then CurrentControlModule:Disable()end setJumpModule(l)CurrentControlModule=w if CurrentControlModule and not IsModalEnabled then CurrentControlModule:Enable()if l then TouchJumpModule:Enable()end end end end elseif UserInputService.KeyboardEnabled then w=function()local w=nil if not IsUserChoice then if DevMovementMode==Enum.DevComputerMovementMode.KeyboardMouse then w=ControlModules.Keyboard elseif DevMovementMode==Enum.DevComputerMovementMode.ClickToMove then w=ControlModules.Keyboard end else if UserMovementMode==Enum.ComputerMovementMode.KeyboardMouse or UserMovementMode==Enum.ComputerMovementMode.Default then w=ControlModules.Keyboard elseif UserMovementMode==Enum.ComputerMovementMode.ClickToMove then w=ControlModules.Keyboard end end if w~=CurrentControlModule then if CurrentControlModule then CurrentControlModule:Disable()end CurrentControlModule=w if CurrentControlModule then CurrentControlModule:Enable()end end end end
--
local onControlsChanged = nil
if IsTouchDevice then
	createTouchGuiContainer()
	onControlsChanged = function()
		local newModuleToEnable = nil
		local isJumpEnabled = false
		if not IsUserChoice then
			if DevMovementMode == Enum.DevTouchMovementMode.Thumbstick then
				newModuleToEnable = ControlModules.Thumbstick
				isJumpEnabled = true
			elseif DevMovementMode == Enum.DevTouchMovementMode.Thumbpad then
				newModuleToEnable = ControlModules.Thumbpad
				isJumpEnabled = true
			elseif DevMovementMode == Enum.DevTouchMovementMode.DPad then
				newModuleToEnable = ControlModules.DPad
			elseif DevMovementMode == Enum.DevTouchMovementMode.ClickToMove then
				-- Managed by CameraScript
				newModuleToEnable = nil
			elseif DevMovementMode == Enum.DevTouchMovementMode.Scriptable then
				newModuleToEnable = nil
			end
		else
			if UserMovementMode == Enum.TouchMovementMode.Default or UserMovementMode == Enum.TouchMovementMode.Thumbstick then
				newModuleToEnable = ControlModules.Thumbstick
				isJumpEnabled = true
			elseif UserMovementMode == Enum.TouchMovementMode.Thumbpad then
				newModuleToEnable = ControlModules.Thumbpad
				isJumpEnabled = true
			elseif UserMovementMode == Enum.TouchMovementMode.DPad then
				newModuleToEnable = ControlModules.DPad
			elseif UserMovementMode == Enum.TouchMovementMode.ClickToMove then
				-- Managed by CameraScript
				newModuleToEnable = nil
			end
		end
		setClickToMove()
		if newModuleToEnable ~= CurrentControlModule then
			if CurrentControlModule then
				CurrentControlModule:Disable()
			end
			setJumpModule(isJumpEnabled)
			CurrentControlModule = newModuleToEnable
			if CurrentControlModule and not IsModalEnabled then
				CurrentControlModule:Enable()
				if isJumpEnabled then TouchJumpModule:Enable() end
			end
		end
	end
elseif UserInputService.KeyboardEnabled then
	onControlsChanged = function()
		-- NOTE: Click to move still uses keyboard. Leaving cases in case this ever changes.
		local newModuleToEnable = nil
		if not IsUserChoice then
			if DevMovementMode == Enum.DevComputerMovementMode.KeyboardMouse then
				newModuleToEnable = ControlModules.Keyboard
			elseif DevMovementMode == Enum.DevComputerMovementMode.ClickToMove then
				-- Managed by CameraScript
				newModuleToEnable = ControlModules.Keyboard
			end 
		else
			if UserMovementMode == Enum.ComputerMovementMode.KeyboardMouse or UserMovementMode == Enum.ComputerMovementMode.Default then
				newModuleToEnable = ControlModules.Keyboard
			elseif UserMovementMode == Enum.ComputerMovementMode.ClickToMove then
				-- Managed by CameraScript
				newModuleToEnable = ControlModules.Keyboard
			end
		end
		if newModuleToEnable ~= CurrentControlModule then
			if CurrentControlModule then
				CurrentControlModule:Disable()
			end
			CurrentControlModule = newModuleToEnable
			if CurrentControlModule then
				CurrentControlModule:Enable()
			end
		end
	end
end
