Closing gui with a remoteEvent

I want to close a starting gui, that is visible from the start. I use a script which successfully fires the RemoteEven that is supposed to close the gui.

1
image

image

Local script works. no scripts overwriting each other. gui.enabled = false and Image.visible = false after the remote event, nonetheless the gui is visible. How to fix this?

Did you make sure the client recieved the event?

Also can we see the server side script.

Try putting a print(“Recieved”) between line 6 and 7.
That way you can check.

I’m pretty sure if you want the GUI to not be visible on the player’s screen in the game you should use game:GetService(“Players”).PlayerGUI instead of startergui

I recommend you place all scripts that handle the GUI inside of the starter GUI btw

If a player joins, the GUI from the StarterGUI will be replicated to the Players PlayerGui. So u have to access the Players PlayerGui and change it from there, also i would like to see the Server Code.

Replace the code inside of the CloseGUI LocalScript with this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local closeStarGUI = ReplicatedStorage:WaitForChild("CloseStarGUI")

local starGUI = script.Parent
local imageGUI = starGUI:WaitForChild("ImageLabel")

local function onClientEvent()
	starGUI.Enabled = false
	imageGUI.Visible = false
end

closeStarGUI.OnClientEvent:Connect(onClientEvent)
2 Likes

Thank you so much for a detailed feedback! :star_struck: You helped me out a lot, appreciate it a lot. I wonder if you could point out the main reason why my version of the script didnt work? In order
not to repeat the same mistake in the future.

1 Like

Since the code is written inside of the LocalScript that’s inside of your Gui, it was possible to fetch the Gui by using script.Parent which also guaranteed you were changing the properties of the correct Gui instead of the one inside of StarterGui. I also recommend using :WaitForChild when fetching an Instance from its parent inside of a LocalScript, since it might not have loaded in time for the player to successfully retrieve the ImageLabel before the script tries to change its Visible property

1 Like

Remote events are not good for closing and opening guis

consider JUST setting the bool value of .Visible on the gui element