How to turn off and on TouchGui

hi, so I’m trying to make a button that disabled and enabled TouchGui but I’m struggling to make it

i found this but so far but it doesn’t help me that much or i just don’t understand it Disable mobile controls temporarily

I mean it explains pretty well in the post you’ve linked.

Just put this in a local script?

local player = game.Players.LocalPlayer

local EnabledTouchGui(bool)
  local TouchGui = player.PlayerGui:FindFirstChild('TouchGui')

  if TouchGui then
    TouchGui.Enabled = bool
  end
end

wait()

EnableTouchGui(false)

where do i put this localscript?

First try under the button, if that doesn’t work then idk.

Put this script under StarterGui

so it doesn’t work for me it said
Players.CooingPizzaboy83.PlayerGui.LocalScript:3: Incomplete statement: expected assignment or a function call

Whoops I mistyped something

local player = game.Players.LocalPlayer

local function EnabledTouchGui(bool)
  local TouchGui = player.PlayerGui:FindFirstChild('TouchGui')

  if TouchGui then
    TouchGui.Enabled = bool
  end
end

wait()

EnableTouchGui(false)
local UserInputSerive = game:GetService("UserInputService")

local player = game.Players.LocalPlayer

local function EnableTouchGui(bool)
   if not UserInputService.TouchEnabled then return end
   local TouchGui = player:WaitForChild("PlayerGui"):WaitForChild("TouchGui")
   TouchGui.Enabled = bool
end
1 Like

sorry for the long delay i was eating so now the error said
Players.CooingPizzaboy83.PlayerGui.LocalScript:13: attempt to call a nil value

Add a print in the function to see whats nil

local function EnabledTouchGui(bool)
  print(player) 

  local TouchGui = player.PlayerGui:FindFirstChild('TouchGui')

  print(TouchGui) 

  if TouchGui then
    TouchGui.Enabled = bool
  end
end

And just double check if your script is a local script.

where do i put this is it in startergui? just to make sure

The refrence code that @dandcx gave, you can create a local script in the startergui and paste the code in there:

And you can add the prints to the function as I said before to see whats nil.

i don’t get it, i see no errors but it doesn’t hide the Mobile Controls