UserInputService.ModalEnabled does not disable mobile controls

The code example on the wiki, which says disables and enables the mobile controls every five seconds, does not work in the emulator nor on a real mobile device. Anyone know why?

The code is in a local script in StarterPlayerScripts.

Hi! Can you show me the script, please?

This is literally it.


--// Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local PlayerService = game:GetService("Players")


--// Constant
local LocalPlayer = PlayerService.LocalPlayer
local PlayerScripts = LocalPlayer.PlayerScripts
local ThumbstickModule = PlayerScripts:WaitForChild("PlayerModule"):WaitForChild("ControlModule"):WaitForChild("TouchThumbstick")

while true do
	UserInputService.ModalEnabled = not UserInputService.ModalEnabled
	wait(5)
end

Try this one:

--// Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local PlayerService = game:GetService("Players")


--// Constant
local LocalPlayer = PlayerService.LocalPlayer
local PlayerScripts = LocalPlayer.PlayerScripts
local ThumbstickModule = PlayerScripts:WaitForChild("PlayerModule"):WaitForChild("ControlModule"):WaitForChild("TouchThumbstick")

while true do
    if UserInputService.ModalEnabled == true then
	    UserInputService.ModalEnabled =false
    else
        UserInputService.ModalEnabled = true
    end
	wait(5)
end

The code does the same thing, which in turn still does nothing.

1 Like

Are you trying to disable mobile players from moving?

If so, I suggest anchoring the player cause .ModalEnabled = false doesn’t stop the player from moving to my knowledge, it’s to toggle if they can see the controls

If he was trying to do that he would have said that he was trying to prevent mobile players from moving. What Joe and I want to do is re-write to mobile controls to be custom for our own purposes.

If you haven’t already, try looking at this, and scroll down to where it says Mobile controls, you can set it to scriptable, I haven’t tried to do it but I believe that’s how you would do it

You can use the PlayerModule:GetControls() and use Enable and Disable to do what ModelEnabled is supposed to. However you will need to override the methods to add in the touchGui.

Here is a way to override the default Enable an Disable methods without needing to folk the code. Create a LocalScript in the StarterPlayer.StarterScripts and place the following code in that script.

local LocalPlayer = game:GetService("Players").LocalPlayer
local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")
local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))
local PlayerControls = PlayerModule:GetControls()

-- keep the default Enable and Disable methods as we will still call them
-- this allows an override without having to fork the code
PlayerControls.EnableFix = PlayerControls.Enable
PlayerControls.DisableFix = PlayerControls.Disable

function PlayerControls:Enable(enable)
	if enable == nil then
		enable = true
	end
	if enable then
		if self.touchGui then
			self.touchGui.Enabled = true
		end
		self:EnableFix(enable) -- run the original Enable to let it do what it does
	else
		self:Disable()
	end
end

function PlayerControls:Disable()
	if self.touchGui then
		self.touchGui.Enabled = false
	end
	self:DisableFix() -- run the original Disable to let it do what it does
end

After the script executes anytime PlayerControls Enable and Disabled are called the touchGui will also enable and disable. This is true when requiring the PlayerModule from other scripts as well.

View the update here on the upcoming fix (link updated):

1 Like