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.
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.
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).
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.
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.
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.
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