I want to turn off mobile controls when a player clicks a GuiButton.
Everybody says to use UserInputService.ModalEnabled, but that seems to not work. Even after waiting 5 seconds before trying to enable it, it doesn’t turn off the touchpad or gamepad. I even used print() and it showed that it was, in fact, toggling, but the controls on-screen never disappeared.
I tried looking on the developer hub for solutions, but couldn’t find a way to fix the problem. Here is the (defective) code I used:
local button = script.Parent.TextButton
local UIS = game:GetService("UserInputService")
local x = 0
button.MouseButton1Click:Connect(function()
if x==0 then
wait(0.1)
UIS.ModalEnabled = true
elseif x==1 then
wait(0.1)
UIS.ModalEnabled = false
end
x=1-x
end)
If you can tell me what I did wrong that would be great
i put a print command after the line that changes the ModalEnabled property, and it shows that the line is working.
but the touch controls themselves aren’t hiding or showing after changing it
(and yes the code is in a local script)
I tried several different versions of that code in my script and none of them seemed to work. I even clicked on several side-links that were related and none of them worked. Any other suggestions as to how to make it actually work?
I tried that, but when you turn StarterPlayer.DevTouchMovementMode to Scriptable, it doesn’t let you move at all. And since the poster of that thread wanted there to be absolutely no player movement in his game, it doesn’t work for my game. (an obby game)
because when there is a frame on the screen, the touch-movement GUI gets in the way of the buttons. when i try to set movement speed to 0, the character can’t move while the frame is on screen, but the touch-movement gui is still there, causing a disturbance in the frame.
You can at least hide the jump button by setting the humanoid’s JumpPower to 0. I can’t figure out why the thumbstick won’t disappear, though. It’s probably just a bug, because ContextActionService touch buttons react to ModalEnabled, just not the thumbstick.
Hello, when I needed to use ModalEnabled I found a different way to do it. What I did was make the controls invisible in the players PlayerGui. I don’t remember how to do it, and I don’t have the script anymore, but here’s what it might look like.
Disabling the TouchGui isn’t enough, you also will need to disable the controls. I wrote some samples that took this into account after some testing yesterday.