The properties DevComputerMovementMode
and DevTouchMovementMode
determine how or if a character can move. Ideally, setting them to Scriptable
will prevent movement. In practice, only certain events will trigger that change.
Edit: I thought my solution actually didn’t work, but it does. Here’s a rewrite of the solution.
When the settings changes, this code calls ControlState:SwitchTo
LocalPlayer.Changed:connect(function(property) -- line 285
if lastInputType == Enum.UserInputType.Touch and property == 'DevTouchMovementMode' then
ControlState:SwitchTo(ControlModules.Touch)
elseif UserInputService.KeyboardEnabled and property == 'DevComputerMovementMode' then
ControlState:SwitchTo(ControlModules.Keyboard)
end
end)
ControlState:SwitchTo
doesn’t do any Dev*MovementMode
checked, but ControlModule:Enable
does. ControlState:SwitchTo
should call ControlModule:Enable
, but it doesn’t if it is the same module as it’s already using.
function ControlState:SwitchTo(newControl)
if ControlState.Current == newControl then return end -- line 56
if ControlState.Current then
ControlState.Current:Disable()
end
ControlState.Current = newControl
if ControlState.Current then
ControlState.Current:Enable()
end
end
Here’s the important ControlModule
code, in this case for the Keyboard
module, which is needed to disable default controls.
local function getKeyboardModule() -- line 211
-- NOTE: Click to move still uses keyboard. Leaving cases in case this ever changes.
local whichModule = nil
if not IsUserChoice then
if DevMovementMode == Enum.DevComputerMovementMode.KeyboardMouse then
whichModule = keyboardModule
elseif DevMovementMode == Enum.DevComputerMovementMode.ClickToMove then
-- Managed by CameraScript
whichModule = keyboardModule
end
else
if UserMovementMode == Enum.ComputerMovementMode.KeyboardMouse or UserMovementMode == Enum.ComputerMovementMode.Default then
whichModule = keyboardModule
elseif UserMovementMode == Enum.ComputerMovementMode.ClickToMove then
-- Managed by CameraScript
whichModule = keyboardModule
end
end
return whichModule
end
ControlModules.Keyboard = {}
function ControlModules.Keyboard:Enable()
DevMovementMode = LocalPlayer.DevComputerMovementMode
IsUserChoice = DevMovementMode == Enum.DevComputerMovementMode.UserChoice
if IsUserChoice then
UserMovementMode = GameSettings.ComputerMovementMode
end
local newModuleToEnable = getKeyboardModule()
if newModuleToEnable then
if newModuleToEnable then
newModuleToEnable:Enable()
end
end
end
My quick fix was to comment out line 56. This causes problems with interactions between keyboard/mouse. Regardless, the code I posted shows what it needs to do to enable/disable as soon as it changes.
Final edit: I have submitted a pull request to fix this issue. The fix submitted there is a better/more consistent fix than the one I had provided here.