How can I make my Gui vanish?

  1. What do you want to achieve? I want to make A system where players can buy land and A Gui to do so appears wheN touched. This works but I cannot make it vanish afterwards.

  2. What is the issue? My script fires A remote event in the replicated storage from A script inside of the part to A local script inside of Screen Gui.
    Script:

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("GuiAppear")
function onTouched(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.parent) 
	if player then
	Event:FireClient(player)	
	end 
end

script.Parent.Touched:Connect(onTouched)

Local Script:

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("GuiAppear")

Event.onClientEvent:Connect(function()
	script.Parent.PlotGui.Visible = true
	
end)
  1. What solutions have you tried so far? I tried using if and else-if statements and then setting the visibility to false but I could not make this work.
1 Like

Try something like this:

Event.onClientEvent:Connect(function()
    if script.Parent.PlotGui.Visible then
        script.Parent.PlotGui.Visible = false
    else
        script.Parent.PlotGui.Visible = true
end)

The indentation may be wrong because I’m on mobile rn.

that will work lovethebears, but you can even make it more efficient -

Event.OnClientEvent:Connect(function()
     script.Parent.PlotGui.Visible = not script.Parent.PlotGui.Visible
end)
2 Likes

This works but I am using R15 Models Dunno if their is A difference in R6 but whenever the character moves the Gui vanishes and returns, do I use scripting to fix this?

When would you like the GUI to close? When a button is pressed, or after a certain amount of time?

The Gui will be closed when A button is clicked but it vanished if the player moves whilst it is activated.

You’d want to use the MouseButton1Click event of the button for that.

To close it? I can do that I just do not want the Gui to flicker whilst moving the local script can be seen above.

I’m having a bit of trouble understanding what you want. Do you want the GUI to be toggled when the player hits the part? This means that the GUI will close if it is already open, and open if it is not already.

I will try and explain again: My Gui opens when A part is stood on and closes when someone leaves it. I have managed to do that but now when the player walks on the part the Gui flickers in and out.

You’d need to use Region3 for this. You can use Region3 to reliably check to see if a player is within a certain region.

Edit: I’d recommend that you check out @ForeverHD’s Zone+ module, as it makes this process very simple and straightforward.

1 Like