UIS.ModalEnabled not working for me : (

Hey, so i need some help.

ModalEnabled doesn’t seem to work for me and im trying to hide the player controls on iOS for a UI based game similar to the famous kahoot game online.

I’ve put it at the top of my script, didnt work, i waited 5 seconds before running to “wait for teh core scripts to load”, still didnt work. I’ve set it to true and false and true thern false and false then true, but nothing works. Here are some screenshots of what i’ve tried.

Screenshot_1933

Screenshot_1934

Screenshot_1935

Screenshot_1936

Screenshot_1937

Screenshot_1938

Screenshot_1939

Screenshot_1940

Please help if you can!

EDIT: I fixed the clumped images :expressionless:

2 Likes

There have been complaints about ModalEnabled not working for the longest of time. Setting DevTouchMovementMode to Scriptable from the get-go should get rid of the controls all the same.

10 Likes

Thanks so much! It worked! I’ve been trying to fix this for the past 2 hours but it never worked.

2 Likes
Player.DevTouchMovementMode = Enum.DevTouchMovementMode.Scriptable

15:48:43.608 - Insufficent permissions to set DevTouchMovementMode

15:48:43.609 - The current identity (2) cannot setDevTouchMovementMode (lacking permission 5)

2 Likes

Ah. TIL because I didn’t read documentation: you can’t use this from the client (for whatever reason).

I’ve tried playing around with ModalEnabled and touch controls briefly in Studio: it’s apparent that ModalEnabled serves no purpose anymore. I checked through the legacy and current PlayerScripts to try and get an understanding of things.

The legacy PlayerScripts structure relies on UserInputService.ModalEnabled to determine whether the touch controls should be active or not. However, the functionality is not set up with the current ModalEnabled boolean as an initial state. Therefore, it reads off ModalEnabled and changes the Gui’s visibility only after the user begins interacting with the game world.

The current PlayerScript structure does not incorporate ModalEnabled at all, so the TouchGui is implicitly there. If you want to turn off touch controls, disable them via the PlayerModule and then disable the actual touch controls Gui.

Writing externally:

local LocalPlayer = game:GetService("Players").LocalPlayer
local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local PlayerControls = require(PlayerScripts.PlayerModule):GetControls()
local TouchGui = PlayerGui:FindFirstChild("TouchGui")

PlayerControls:Disable()
if TouchGui then TouchGui.Enabled = false end

PlayerControls:Enable()
if TouchGui then TouchGui.Enabled = true end

Changing the behaviour of enable/disable (fork PlayerModule, edit ControlModule, replace both the enabled and disabled functions with the following):

function ControlModule:Enable(enable)
	if not self.activeController then
		return
	end

	if enable == nil then
		enable = true
	end
	if enable then
		self:EnableActiveControlModule()
		self.touchGui.Enabled = true
	else
		self:Disable()
	end
end

-- For those who prefer distinct functions
function ControlModule:Disable()
	if self.activeController then
		self.activeController:Enable(false)

		if self.moveFunction then
			self.moveFunction(Players.LocalPlayer, Vector3.new(0,0,0), true)
		end
		
		if self.touchGui then
			self.touchGui.Enabled = false
		end
	end
end

It’d be worth writing a Feature Request to make a decisive move on ModalEnabled. It’d be better to just request its removal and have the Disable method of Controls disable the TouchGui (since it stays on if you call Disable).

7 Likes

Don’t know how it’s better to have ModalEnabled removed. I’d much rather have a simple 1 line of code decide on wether to enable to disable rather than setting up all these confusing functions etc.

1 Like

:man_shrugging:

I like the new design of the PlayerModule since it allows for easy modification. With all the shifting and changes to the PlayerModule, ModalEnabled got left out so you’re left to resort to other tricks like this.

I don’t find it confusing but that’s just me. I can agree with cases where it’d be better to allow new developers easy access to properties to flip the Gui and/or controls on and off, which ModalEnabled was supposed to do until new PlayerScripts dropped.

At least you have something that works now?

Copy of the module:
NoTouchControls_PlayerModule_11182019.rbxm (116.7 KB)

If you don’t like my suggestion of putting in a Feature Request to have ModalEnabled removed, you can easily flip that around to request for ModalEnabled to function with the new PlayerScripts structure.

cc @AllYourBlox If you still maintain the PlayerScripts.

1 Like

Hmm ok, ye it seems to work. Thank you!

How can i re-enable it tho without function?

local PlayerControls = require(PlayerScripts.PlayerModule):GetControls()
local TouchGui = PlayerGui:FindFirstChild('PlayerGui')

-- disable
PlayerControls:Disable()
if TouchGui then TouchGui.Enabled = false end

-- re-enable
PlayerControls:EnableActiveControlModule()
TouchGui.Enabled = true -- Error

attempt to index nil with ‘Enabled’

It seemed to work, even though it errored out? How can I clear the error

Oooooooooops, that’s my bad. I wrote out PlayerGui again instead of TouchGui, lol.

local PlayerControls = require(PlayerScripts.PlayerModule):GetControls()
local TouchGui = PlayerGui:FindFirstChild('TouchGui')

-- disable
PlayerControls:Disable()
if TouchGui then TouchGui.Enabled = false end

-- re-enable
PlayerControls:EnableActiveControlModule()
TouchGui.Enabled = true

Fixed on my original sample as well.

P.S. you can also use PlayerControls:Enable().

1 Like

Info here on the upcoming fix (link updated):

1 Like