How to use Proximity Prompt to make UI pop-up

I am trying to use a Proximity Prompt to make a UI pop-up on the user’s screen. I have written the following code:

script.Parent.ProximityPrompt.Triggered:Connect(function()
local ui = game.ReplicatedStorage.OrderingUi
local plr = game.Players.LocalPlayer
ui:Clone().Parent = plr.PlayerGui
 end)

Nothing is outputting. The script is in the model with the Proximity Prompt.

What am I doing wrong??

1 Like

I wouldn’t say parenting a clone of UI to playerGui is the best way, I recommend using RemoteEvent to FireClient. Let me know if you want the code and explanation.

try this

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
local ui = game.ReplicatedStorage.OrderingUi
local GuiLocation = game.Players:FindFirstChild(player.Name).PlayerGui
ui:Clone().Parent = GuiLocation 
 end)

Still not working, and not outputting any errors.

Try to put a print “print(GuiLocation)”

You cannot really access PlayerGui from server, you must use RemoteEvents in order for it to work. So you have to use FireClient and it pretty much is the same thing.

1 Like

Okay the issue you are having is that a local script cannot be in the part it has to be in StarterPlayerScripts or ReplicatedFirst.
You can just switch this to a server script and put the following in it:

You can also do this in a local script as well, just remember you have to put the local script in StarterPlayerScripts or ReplicatedFirst.

game.Workspace.Part.ProximityPrompt.Triggered:Connect(function(plr)
local PlayerGui = plr:WaitForChild("PlayerGui")
local ui = game.ReplicatedStorage.OrderingUi:Clone()
ui.Parent = PlayerGui
 end)

Also make sure you have the Gui enabled so you can see it.
Depending if this is in a server script you can just do script.Parent, if this is in a local script you have to find that part game.Workspace.Part.

Hope this helps!