I am making a GUI for a train. Trains have no need for DPads, Thumbsticks, nor Thumbpads, so I want to make them invisible while the player is seated in the train, then re-enable them when the player jumps out.
I tried to disable all the thumbsticks via their public API, but this method errors on PC when it runs :Disable()
local MasterControl = Player:FindFirstChild("MasterControl",true) -- playing with fire here assuming the first MasterControl will be the module we want
local DPad = require(MasterControl:FindFirstChild("DPad",true))
local Thumbstick = require(MasterControl:FindFirstChild("Thumbstick",true))
local Thumbpad = require(MasterControl:FindFirstChild("Thumbpad",true))
DPad:Disable()
Thumbstick:Disable()
Thumbpad:Disable()
-- on exit
DPad:Enable()
Thumbstick:Enable()
Thumbpad:Enable()
A simpler method is to disable the TouchControlFrame or TouchGui, but this will disable the jump button which is not what I want.
Is there a better method than looking inside the TouchGui, noting which are enabled, and changing their visibility directly?
Don’t know what the problem ie at all but have you made a variable named Player in some other part of the script, because you didn’t list it so I’m not sure. Also can you send a screenshot of the error?
I had a thought about doing this, but it won’t work. The thought was, use getfenv on ControlScript and call ControlModules.Touch:Disable() then TouchJumpModule:Enable() when the player sits, then call ControlModules.Touch:Enable() when they leave. This won’t work, however, because ControlModules is an upvalue and can’t be seen by getfenv.
So with that idea out of the way, my next one is to copy the contents of getTouchModule() and paste it into the gui script which determines what guis to re-enable when the player gets out of the seat.
I was given a tip that I should look at UIS.ModalEnabled. This enables and disables the mobile GUI pretty well, but it works too well because it also disables the jump GUI. So I did some requiring and enabled the jump GUI after turning on Modal:
local MasterControl = Player:FindFirstChild("MasterControl",true) -- playing with fire here assuming the first MasterControl will be the module we want
local TouchJump = require(MasterControl:FindFirstChild("TouchJump"))
MasterControl = require(MasterControl)
UIS.ModalEnabled = true
if UIS.TouchEnabled then
TouchJump:Enable() -- please please please don't crash PC
end
-- later
UIS.ModalEnabled = false
When Modal is turned off, the jump GUI will get disabled if necessary.