UI Only Opens Once (Stops Opening)

I have a script that displays a UI once a ProximityPrompt is activated, and another script on a ‘Close’ button within the UI that closes the UI, however I’m having an issue as once the UI has been closed, it won’t open again when the ProximityPrompt is activated. I’m not sure why this is, so both scripts are below in case one of them is interferring.

ProximityPrompt Script (Opens UI)

> script.Parent.Triggered:Connect(function(player)
> player.PlayerGui.ToolMenu.ToolFrame.Visible = true
> end)

Button Script (Closes UI)

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

Thanks for any help in advance, if I didn’t explain it well enough please let me know.

2 Likes

Is the button parented to a screen Gui or a frame?

2 Likes

You need to handle both events either on server or client side.

1 Like

It’s parented to a frame, which is then parented to a Screen GUI.

Disregard old reply, I didnt read the post lmao.

Assuming the ProximityPrompt is parented to the workspace, and the GUI script is client sided. The reason why the GUI is only opening once is youre setting Visible to true on the server, then setting Visible to false on the client. Now, on your screen its gone, however on the servers side, its still visible. When you change it back to true on the server, nothing really happens, since as far as the server is concerned, its already visible. You can fix this by either making visible/non visible both on the server, or using RemoteEvents

1 Like

Why not use a remote event to handle it on the client instead?

You can use something like this:

local event = game:GetService("ReplicatedStorage"):WaitForChild("OpenUI") -- a remote event called "OpenUI" should be put inside the replicated storage
local Frame = script.Parent.Parent

event.OnClientEvent:Connect(function()
      Frame.Visible = true   
end)

this is local script btw

1 Like

I know why, it’s because the button script is a local script. While the opening script is a Server script.

I have a simple fix.

First, create a RemoteEvent inside replicated storage.

next, update the prox script to be this:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- change the RemoteEvent to the remote event's name
script.Parent.Triggered:Connect(function(player)
	 remote:FireClient(player)
end)

Then, create a Local Script inside of your ui and do this.

local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- change the RemoteEvent to the remote event's name

remote.OnClientEvent:Connect(function()
	script.Parent.Visible = true
end)

if you have any questions feel free to ask :slight_smile:

@ar3lle

4 Likes

Should the Local Script be parented to the Continue button or the UI that’s being opened? Sorry, I’m pretty new to this stuff as you can probably tell.

Parent it to the UI that’s meant to be opened.

1 Like