Can't Figure Out How to Use Modal Enabled

Hello. I am trying to disable the default mobile controls on my game so I can make custom ones. I need to do that because I want to make the player only be able to move left and right. I am unable to use Modal Enabled. I don’t know if I’m doing something wrong, or if it’s broken right now. I have been trying to find out what I’m doing wrong for a while, and I can’t find anything that works. Here is the script I was using.

wait(0.5)
game:GetService('UserInputService').ModalEnabled = true

(The wait is so the player’s CoreGui can load before it goes off.)
This is a local script. I have tried putting it everywhere I could think of that might work. I tried StarterPack, StarterPlayer.StarterCharacterScripts, and StarterPlayer.StarterPlayerScripts. None of these worked.

Thank you for taking the time to read this!
Have a nice day!

ModalEnabled has an unattended issue where calling it too fast will not appropriately change the state of the control Guis. This has been a problem for a few years and even I didn’t know how to disable mobile controls, so I just completely removed them or disallowed mobile users to play my game.

You need to account for the initialisation case yourself. You can do that in many ways:

  • Setting ModalEnabled to false when the character spawns
  • Handling changes in UserInputService
  • Hacking together a solution
  • Mashing your keyboard and hoping this works

Here’s an example snippet of code I went and searched up.

UserInputService.ModalEnabled = true
delay(1, function()
    UserInputService.ModalEnabled = false
    UserInputService.ModalEnabled = true
end)
7 Likes

More info here on the upcoming fix:
https://devforum.roblox.com/t/mobile-controls-toggle-fix-for-modalenabled-upcoming-deprecation/1258538