Having Issues with how to open and close a GUI with a proximity prompt

I am trying to make a menu for my game, which I have open with a proximity prompt. I open it, then close it, but after the 2nd time I open, then close it, it wont open again. I had this issue before on another project, but I forgot how to fix it.

(Normal Script which is triggered after proximity prompt is used)

script.Parent.Triggered:Connect(function(player)
	print(player.Name .. " has triggered the prompt.")
	if not player.PlayerGui:FindFirstChild("ScreenGui") then
		print("yes")
		local gui = game.ServerScriptService.ScreenGui:Clone()
		gui.Parent = player.PlayerGui
	else
		player.PlayerGui.ScreenGui.MainGUI:TweenPosition(UDim2.new(0.169, 0, 0.173, 0),1,2,1)
	end
end)

Here is my close script (Local Script)

script.Parent.CloseGUI.MouseButton1Click:Connect(function()
	script.Parent:TweenPosition(UDim2.new(0.169, 0,1, 0),0,2,1)
end)

I tried destroying the GUI when closed, but that didnt seem to work

BTW, I am getting xA_xsin has triggered the prompt, when it doesnt pop back up (It may be stuck at the closed position)

Here is a GIF of it happening. Roblox (gyazo.com)

I believe this is happening because you’re opening the UI on the server, however you’re closing it on the client. It might be a better idea to fire a remote to the client to open the UI as well, rather than having that take place on the server.

3 Likes

try adding a debounce variable

Proximity prompts don’t work with server scripts, consider using a RemoteEvent

ProximityPrompts work with server scripts, the actual issue has been explained here.

Thanks! I got a response faster in HD saying the same thing and it did work.

I meant to put local script not server script, I saw local script so mistakingly thought that their proximity prompt was running on the client.