How to make a Surface GUI open a Frame?

Tyring to make it so if someone hits a suface GUI button a frame becomes Visible. Can someone help?

All I got is this in a script

local Frame = game.StarterGui.Question1.Q1

I am a starter at scripting.

So when you start a game everything in game.StarterGui gets copied in a special folder called Player.PlayerGui

Put this in a normal Script inside the button

script.Parent.MouseButton1Click:Connect(function(player)
    player.PlayerGui.Question1.Q1.Visible = true
)

This should work, feel free to reply if you need anymore help.

What you have is a variable which is a good start.

Now make a function for when the button is pressed:

local Frame = game.StarterGui.Question1.Q1

local Button = --Put where your button is located there

button.Activated:Connect(function(plr)
        plr.PlayerGui.Question1.Q1.Visible = true
end)

Here is the documentation on In-Experience UI Containers | Documentation - Roblox Creator Hub

Shouldn’t the line after THEN be = and not ==

1 Like

This did not work when I tryed it

Try a local script in StarterGui with the same script but put the full path

game.Workspace.-full path here-.MouseButton1Click:Connect(function()
    script.Parent.Question1.Q1.Visible = not script.Parent.Question1.Q1.Visible 
)

What do you mean by full path?

Something like

workspace.Part
1 Like

Still did not work. Do you need more decription of what I am looking for?

Are you getting any errors in the console? Press F9 or type /console

Yes I am


edited script

game.Workspace.Question1S.Screen.SurfaceGui.TextButton.MouseButton1Click:Connect(function()
	script.Parent.Question1.Q1.Visible = not script.Parent.Question1.Q1.Visible 
end)
1 Like

Hmm, could you show us a picture of what your button’s children are?

Which Button? The text button? And whats a child again?

The child is a Script.

I believe

Learning Scriptingbe like

ok so I’ve had this problem before, what you would need to do is code this client-side because there is no good way to get the player from the click of a GUI server-side

so in a local script in StarterGui or wherever code what you want the button to do when it is clicked and you can use game.Players.LocalPlayer to open the GUI because your listening for the clicks client-side

heres something i wrote to help you
This is a local script in StarterGui
hope this helps if you need any more help don’t hesitate to ask

local player = game.Players.LocalPlayer
local Button = workspace.SurfacePart.SurfaceGui.TextButton

Button.MouseButton1Down:Connect(function()
	player.PlayerGui["ScreenGuiName"]["FRAME"].Visible = true
	
	-- if you want it to dissapear when they click it again then do this instead
	--[[
		player.PlayerGui["ScreenGuiName"]["FRAME"].Visible = not player.PlayerGui["ScreenGuiName"]["FRAME"].Visible
	]]
end)
3 Likes