ProximityPrompt don't work

I created simple local script to ProximityPrompt that was to enable PlayerGui “Test” after trigering but it don’t work. I don’t know what to do, please help.

There is script:

local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local ui = PlayerGui:WaitForChild("test")

script.Parent.ProximityPrompt.Triggered:Connect(function()
	ui.Enabled = true
end)

There is no need to use LocalScript, simply use normal Script and get player using ProximityPrompt.Triggered.

Edit: You can use FindFirstChild instead of WaitForChild, when player interacts with the proximity prompt it means they are already fully loaded into the game. So you are 100% sure their PlayerGui is loaded into the server.

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	local PlayerGui = plr:FindFirstChild("PlayerGui")
	local ui = PlayerGui:FindFirstChild("RobienieDowodu")
	ui.Enabled = true
end)
1 Like

your code looks fine, i just cleaned it up a little bit.

  • check to see if your proximity prompt is in a part
  • is it enabled?
  • are u referencing your UI incorrectly? just check to make sure
  • make sure it’s a local script, put it in StarterPlayerScripts
local ProximityPrompt = script.Parent.ProximityPrompt

ProximityPrompt.Triggered:Connect(function(Player)
local PlayerGui = Player.PlayerGui
local ScreenGui = PlayerGui:WaitForChild("RobienieDowodu") -- if it is a screengui

	ScreenGui.Enabled = true
end)
1 Like

You should not use a server script to handle GUI. The client should be the one handling UI for a smooth experience, as they are the ones seeing and interacting with the UI, not the server, to avoid latency, and input delay and also to not create inconsistencies with replication (if you use local scripts to change the UI, and then use the server to revert that for example, the server would still think the UI is visible)

See here


For this to work, you either should to use a local script in a place where it can run, assuming your proximity prompt is a descendant of the workspace - local scripts can’t run there, and then reference your proximity prompt’s path correctly. (This is what @targetdior suggested, it is a good option)

Or alternatively, you can use a script with the RunContext property set to client.

You can also fire a remote event from a server script parented to the proximity prompt, to player that triggered the proximity prompt (it is given to you as a parameter)

All of these options are valid, though for your case I’d suggest setting the RunContext to client and putting the script under your proximity prompt, as that is the easiest way to reference the proximity prompt.

local Proxy = workspace:WaitForChild("Part"):WaitForChild("ProximityPrompt")

--FOR LOCAL PLAYER ONLY

local localPlayer = game.Players.LocalPlayer
local UI = localPlayer.PlayerGui:WaitForChild(YOURSCREENUI)

Proxy.Triggered:Connect(function(playerTrigger)
	if playerTrigger == localPlayer then
		UI.Enabled = true
	end
end)

--FOR ALL PLAYER / SERVER SCRIPT

Proxy.Triggered:Connect(function(playerTrigger)
	local UI = playerTrigger.PlayerGui:FindFirstChild(YOURSCREENUI)
	if UI then
		UI.Enabled = true
	end
end)

Hi, i think the part that makes this script not work, is the LocalScript is not inside of the ProximityPrompt. I reviewed all the replies and people seemed to miss this detail, i think you should move the LocalScript into the ProximityPrompt, since local scripts only work in client owned environments. (PlayerScripts, PlayerGUI, Camera, etc.) The way proximity prompts work, is that on the instantiation of the prompt, it will be cloned inside of all the players playerGUI in the game.Players dictionary along with all of its descendants.

Sorry if you didnt understand something, my main language isnt english, so let me know if you need clarification on something.

I believe your proximity prompt is located in workspace. Client scripts don’t work in workspace, but if you insist on using them, create a normal script with Client RunContext.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.