Can you help me fix this script?

Hiya Developers!

I have a script witch closes a UI when pressed, but how do i make my script work for Mobile and PC players?

Here is my script:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Visible = false
end)

Connect TouchTap as well.

local ui: GuiBase2D = script.Parent

local function onUIClicked()
	ui.Visible = false
end

ui.TouchTap:Connect(onUIClicked)
ui.MouseButton1Click:Connect(onUIClicked)

Thanks alot, ill try this now!

Does this belong to a SurfaceGui which is a parented to part in the workspace?

workspace.Part.SurfaceGui.TextButton.MouseButton1Click:Connect(function()
	workspace.Part.SurfaceGui.TextButton.Visible = false
end)

Local script inside StarterPlayerScripts folder.

Its a ScreenGUI Not is a Surface GUI.

Capture

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Visible = false
end)

Local script, I’ve tested and this works. If you instead want to disable the ScreenGui then you can use the following instead.

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Enabled = false
end)
1 Like

I see you need it to work for mobile users too, as such add the following to the previous script.

script.Parent.TouchTap:Connect(function()
	script.Parent.Visible = false
end)
1 Like

Thanks, this script is now working!