ProximityPrompt only works once

I want to make a UI pop up when a proximity prompt is triggered, but it only works once.

Here is the code that shows the UI

script.Parent.Triggered:Connect(function(player)
	local orderGui = player.PlayerGui:WaitForChild("SmartCafe")
	
	if orderGui.Enabled == false then
		orderGui.Enabled = true
		script.Parent.Enabled = false
	end
end)

Here is the script that closes the UI (UI button)

local screengui = script.Parent
local itemsFrame = screengui.Items

local exitItems = itemsFrame.Exit

exitItems.MouseButton1Click:Connect(function()
	if screengui.Enabled == true then
		screengui.Enabled = false
		game.Workspace["Cafe Register"].ProximityPart.ProximityPrompt.Enabled = true
	end
end)

I saw another devforum post on this but it was no help

1 Like

Is this done from a server-sided script?

Yes, it is a server-side script

This happens because you disable the ProximityPrompt when it is triggered.

(See code with 3 asterisks on each side)

You would either need to re-enable it in the script that closes the UI, or remove it entirely.

I did that on the 9th line of code on the script that closes the UI, when I test it I can see in the properties that the prompt clearly gets enabled again it just doesnt work

The proximity prompt getting enabled works fine in the script that closes the UI. The problem is the UI itsself. Since he’s enabling it on server-side and disabling on client, the server still registers the GUI as enabled and the proximity prompt doesn’t enable it.

Actually there is no proximity prompt that closes the UI, just a regular TextButton, I also disable on a regular script and enable on a client script

Sorry, I meant about the proximity prompt being enabled again through it.

You are disabling the parent ScreenGui in the Close UI script, which will also disable its descendants, including LocalScripts. Therefore, the LocalScript is disabled before it can finish this line:

game.Workspace["Cafe Register"].ProximityPart.ProximityPrompt.Enabled = true

You should be making the children of the ScreenGui not visible, not disabling the entire thing, so the LocalScript can continue executing commands.

There are other numerous issues with this script, like the one @Korbloxster brought up, but I’ll let them deal with that.

You can fix this by either:

  1. Sending a remote event to disable the gui from the local script
  2. Check through the prompt script if its already enabled, so it toggles it
script.Parent.Triggered:Connect(function(player)
	local orderGui = player.PlayerGui:WaitForChild("SmartCafe")
	
	if orderGui.Enabled == true then
		orderGui.Enabled = false -- Honestly this is the best i came up with. It checks if its enabled, disables it, and so on
	end

	if orderGui.Enabled == false then
		orderGui.Enabled = true
		script.Parent.Enabled = false
	end
end)
  1. Add a server-sided script to the button instead, so it disables the gui from the server.

I can’t really find more solutions to this. If this doesn’t fix your problem then idk.

I updated the scripts,

Proximityprompt

script.Parent.Triggered:Connect(function(player)
	local orderGui = player.PlayerGui:WaitForChild("SmartCafe"):WaitForChild("Main")
	
	if orderGui.Visible == false then
		orderGui.Visible = true
		script.Parent.Enabled = false
	end
end)

Button

local screengui = script.Parent
local mainFrame = screengui.Main

local exitItems = mainFrame.Exit

exitItems.MouseButton1Click:Connect(function()
	if mainFrame.Visible == true then
		mainFrame.Visible = false
		game.Workspace["Cafe Register"].ProximityPart.ProximityPrompt.Enabled = true
	end
end)

but it still only works once

Let me try your solutions real quick

Number 3 fixed my problem, thanks!

The problem with that is it will re-enable the ProximityPrompt for the entire server. The only ideal solution here is to use a RemoteEvent. If you don’t know how, I’ll guide you through it.

  1. Create a RemoteEvent instance called something like “PromptEnabler” and place it in ReplicatedStorage.
  2. In the Close UI LocalScript, replace…
game.Workspace["Cafe Register"].ProximityPart.ProximityPrompt.Enabled = true

with…

game.ReplicatedStorage.PromptEnabler:FireServer() -- Replace PromptEnabler with whatever you named it
  1. In the ProximityPrompt script, put this:
script.Parent.Triggered:Connect(function(player)
	local orderGui = player.PlayerGui:WaitForChild("SmartCafe")
	
	orderGui.Enabled = true
    script.Parent.Enabled = false
end)
game.ReplicatedStorage.PromptEnabler.OnServerEvent:Connect(function() -- Replace PromptEnabler with whatever you named it
    script.Parent.Enabled = true
end

I tried

local screengui = script.Parent
local mainFrame = screengui.Main

local exitItems = mainFrame.Exit

exitItems.MouseButton1Click:Connect(function()
	if mainFrame.Visible == true then
		mainFrame.Visible = false
		game.ReplicatedStorage.SmartCafeUIEnabler:FireServer()
	end
end)

in the LocalScript and

script.Parent.Triggered:Connect(function(player)
	local orderGui = player.PlayerGui:WaitForChild("SmartCafe"):WaitForChild("Main")

	orderGui.Visible = true
	script.Parent.Enabled = false
end)

game.ReplicatedStorage.SmartCafeUIEnabler.OnServerEvent:Connect(function() -- Replace PromptEnabler with whatever you named it
	script.Parent.Enabled = true
end)

in the prompt script but it still won’t work