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
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.
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:
Sending a remote event to disable the gui from the local script
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)
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.
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)
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.
Create a RemoteEvent instance called something like “PromptEnabler” and place it in ReplicatedStorage.
game.ReplicatedStorage.PromptEnabler:FireServer() -- Replace PromptEnabler with whatever you named it
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
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)