BASIC QUESTION: Gui Is Not Being Visible Again After The Part Is Touched Once

Hey Robloxians,
I made a script which opens a gui when part is touched. However the script breaks if the part is touched once. The GUI do open but the script doesn’t seem work at all after the part is touched. There are no errors in the output. The script is really basic and I don’t see any errors in it, can someone help?

SCRIPT:

local brick = game.workspace.OpenGui

brick.Touched:Connect(Function(hit)
  if hit and hit.Parent then
  script.parent.Visible = true
end)
5 Likes

You have not finished the if statement at line 4.
there should be another end.
Also Function on line 4 should start with an uppercase letter, it should be function.

3 Likes

oh i have fixed it but it still works only one time and then breaks when the part is touched again:

local brick = game.Workspace.OpenGUI

brick.Touched:Connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Visible = true
	end
end)
2 Likes

What do you mean by “breaks”? Did you put a print statement in your Touched event and see if it is indeed still calling that event and it isn’t? Is there somewhere else in your code where you are setting the script.Parent.Visible = false? If not nothing would ever change as it would always be visible from that point on.

3 Likes

I have tried tons of script modification from basic to a little advanced and saw many tutorials but still the gui becomes visible for the time the part is touched once, and then there is no error in output, i didn’t write at break or return in script but still the script stops working something like its disabled

3 Likes

This implies to me the issue is with whatever code makes it disappear. Seeming that the close function either makes another part invisible that this doesn’t handle, or just destroys the gui.

2 Likes

I would recommend you to change the UI visibility on a local script rather then a server script.

You could do all of this through a Remote Event.

Example

Server Script:

local brick = game.Workspace.OpenGUI
local RemoteEvent = game.ReplicatedStorage.RemoteEvent --place your remote event in ReplicatedStorage and reference it here

brick.Touched:Connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		RemoteEvent:FireClient()
	end
end)

Local Script:

local localPlayer = game.Players.LocalPlayer
local PlayerGui = localPlayer.PlayerGui
local OpenGui = PlayerGui.OpenGui --reference your gui here

local RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent.OnClientEvent:Connect(function()
	OpenGui.Visible = true
end)

5 Likes

No, the part and gui both are there, its just something with the script. I even tried something like this:

script.Parent.touched:Connect(function(hit)
  Local plr = game.Players.GetPlayerFromCharacter(hit.parent)

  If plr then 
       plr.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame").Visible = true
  end
end)
3 Likes

I will try both and this and share the results

1 Like

Can you include the snippet of code that handles closing your gui? As far as I can tell, the opening part should work. So the only potential issue I can see is that closing it is changing a state that the opening script isn’t handling correctly.

2 Likes

I agree this is why I was asking where the Visible was set to false. Sometimes people move the Gui to slide it off the screen or set the background transparent instead which would make the Visible useless after the first time.

2 Likes

Possible one is a local script and the other is a server script so it doesn’t update when the local script makes changes.

2 Likes

this is the close button script:

script.Parent.MouseButton1Click:Connect(function()
	local frame = script.Parent.Parent
	
	if frame.Visible == true then
		frame.Visible = false
	else
		frame.Visible = false
	end
end)
2 Likes

Are both of the scripts LocalScripts?

2 Likes

yes both of the scripts and the close button script too are localScripts

2 Likes

this doesn’t seem to be working

2 Likes

same issue (word limit_____________)

1 Like

Hmm… Yeah I’m not sure, the last thing I can think of is maybe script.Parent.Parent of the close script is not equal to script.Parent of the open script. Though I don’t think that’s particularly likely.

2 Likes

Can you show a picture of your Explorer window with your Gui layout(if it differs that is)? I replicated what I assume is your layout, StarterGui, ScreenGui under StarterGui, Frame under ScreenGui along with the LocalScript for the part Touched event, Button under Frame with LocalScript to make invisible and it works with no problems. I did change the close button a bit because there is no need to have an IF statement and put the same code in both the true and false case so it was just:

script.Parent.MouseButton1Click:Connect(function()
	local frame = script.Parent.Parent
	frame.Visible = false
end)

Here is my setup:
image

If you do have this exact layout all I can suggest is close and restart Roblox Studio.

2 Likes

you can’t put your gui inside of your part
try getting the player name from the hit and then make the gui visible from the playergui

2 Likes