When pressing a button it should open another gui (not working)


(THE GUI THAT SHOULD OPEN)

image

The script probably loads faster than the GUI itself. Try putting the script inside the OpenButton, that might solve it. And/or use :WaitForChild
Example:

local Button = ScreenGui:WaitForChild("OpenButton")

This is because you’re not using “MouseButton1Click”, using “Activated” isn’t a valid usage of GUI.

local Player = game:GetService("Players").LocalPlayer

local PlayerGui = Player.PlayerGui

local Frame = PlayerGui.ScreenGui

local Button = PlayerGui.ScreenGui.OpenButton

Button.MouseButton1Click:Connect(function()
frame.Visible = false
end)

But it is, here’s the documentation
https://developer.roblox.com/en-us/api-reference/event/GuiButton/Activated
“Fires when the button is activated.”

1 Like

Thank you so much everybody!! Thanks for your time

1 Like

This detects after it’s been clicked, not to process a click.

I actually worded it wrong, so I apologize, I was meaning it wasn’t a valid use for registering clicks.

I’d recommend putting the LocalScript in the ScreenGui and using this source.

local screengui = script.Parent
local button = screengui:WaitForChild("OpenButton")
local target = screengui:WaitForChild("Frame")

button.MouseButton1Up:Connect(function()
	if typeof(target) == 'Instance' and target:IsA("GuiObject") then
		target.Visible = true -- or you can do 'target.Visible = not target.Visible' for a toggle.
	end
end)
1 Like

If something worked, mark a message as solution, so that this can close.

Oh okay, I didn’t know that. In this case, they should reword the documentation, I’m sure I’m not the first one who got confused

Oh yeah for sure, it is confusing. For a little clarification, Activated can be used if you’re going from a script to another, like if you use “MouseButton1Click” in one script, and then another script will pick up when it got activated.

1 Like
-- Variables
local gui = script.Parent
local Button = gui.OpenButton
local Frame = gui.Frame

-- Function
Button.MouseButton1Click:Connect(function()
frame.Visible = false
end)