Issue with creating a click to open gui

So I have been trying to create a gui that opens when the player clicks the computer screen. I tried it myself and watched a few videos but for some reason, it still doesn’t work the way I want it. When the player clicks on the screen, the gui opens and I created a button that closes it whenever the player is done viewing it. However, when the player goes to click the screen again, it prints that the button was clicked in output but the gui doesn’t pop-up. Can someone help me fix this or give me tips? I’m really new the scripting BTW.

This is the local script that I put my gui inside of. I’m pretty sure this controls whether or not it pops up again or not. Not sure how I can change this so that if the gui is closed it can reopen once the brick gets reclicked.

local gui = script.ScreenGui

local ComputerScreenClickedEvent = game.ReplicatedStorage.Events.ComputerScreenClicked

ComputerScreenClickedEvent.OnClientEvent:Connect(function()

gui.Enabled = true

end)

2 Likes

You’re using a remote event for a simple UI to open when you click? Not necessary.

YourGui = --Just reference your Gui here, use FindFirstChild for better referencing

YourGui.MouseButton1Click:Connect(function()
YourGui.Visible = true

end)

3 Likes

Would I need a script in the clickdetector if I use this or not? My current script in the brick is:

local clickDetector = script.Parent
local ComputerScreenClickedEvent = game.ReplicatedStorage.Events.ComputerScreenClicked
local debounce = false

clickDetector.MouseClick:Connect(function(player)

if not debounce then debounce = true
ComputerScreenClickedEvent:FireClient(player)
print(player.Name… “Clicked the screen”)
wait(.1)
debounce = false
print(“Function can be used again”)
end
end)

1 Like

Are you trying to make a GUI visible by clicking on a part? or by clicking a TextButton?

1 Like

On a part. Which in my case is just a computer screen

1 Like

Yeah, do it on the client side still.

YourPart = --The part you want to reference goes here
YourGui = --Same thing here

YourPart.ClickDetector.MouseClick:Connect(function()
YourGui.Visible = true
end)
1 Like

This should help you.
Please note this is a script not a localscript
For that part use PlayerWhoClicked to find the player who clicked

This is not a full script as Scripting Support is not to ask for scripts. It is for help with scripts.

function onClicked(playerWhoClicked) 
	local playerWhoClicked = playerWhoClicked
        playerWhoClicked.PlayerGUI.GUI.Frame.Visible = true
	end


script.Parent.ClickDetector.MouseClick:connect(onClicked)
1 Like

Don’t recommend using a script for opening a Gui.

1 Like

I know, but it is a start to what @TooMuchRice is trying to achieve.

Thanks for reminding me as I almost would have forgotten.

1 Like

So would this work?

local ComputerScreen = Workspace: FindFirstChild (“ComputerScreen”)
local ScreenGui = StarterGui:FindFirstChild (“ScreenGui”)

ComputerScreen.ClickDetector.MouseClick:Connect(function()
ScreenGui.Visible = true
end)

1 Like

Don’t reference Guis by “StarterGui”. Specially in client sided code.

Reference the player.

local player = game.Players.LocalPlayer

--Then simply do:

player.PlayerGui.YourGui.Visible = true

Is there any other way to open a gui?

When I said script, I meant a regular script. When opening a gui you should use a local script.

Yes, you can use a RemoteEvent, but It’s really unecessary.

1 Like

I see. You meant “server script”.

I’m getting this error

[ServerScriptService.Script:7: attempt to index upvalue ‘player’ (a nil value)]

Are you using a local script? Show me a screenshot of the explorer.

It actually works I was tripping. But it doesn’t open after I close it the first time.

Nevermind I figured it out thanks!