Why does my proximity prompt not work?

i have a model with a proximity prompt, it gets copied from replicated storage and gets put in workspace, but i when i try to use the proximity prompt the script that handles it doesn’t print anything or do anything

script.Parent.Triggered:Connect(function()
	if script.Parent.ActionText == "Open" then
		game.Players.LocalPlayer.PlayerGui.ScreenGui["Door Menu"].Visible = true
	else
		game.Players.LocalPlayer.PlayerGui.ScreenGui["Door Menu"].Visible = false
	end
end)
3 Likes

have you checked if the ActionText is “Open” while playing?

1 Like

yes, i trying adding a print() to the start of the function and it didnt print anything

2 Likes

Then try making a RemoteEvent and put in the ReplicatedStorage and then fire the client

2 Likes

Is the Proxyprompt Enabled, also do you have MaxActivationDistance set to 0?

4 Likes

the issue isnt with the proximity prompt its with the code

2 Likes

that doesnt seem to work, i dont know if theres an issue with my code


2 Likes

I think it is because you are trying to run a local script inside of the workspace.
Local scripts only run on client environments, I assume this is a local script because you are using the .LocalPlayer object.

Solution: move the script to PlayerGui along with the door you’re using.

2 Likes

i dont know how i would do that, because i have a building system down and you can place multiple doors/objects

2 Likes

Make a dedicated local script for the doors, and take advantage of a remote event from the server by using something like this;

server

prompt:Triggered:Connect(function(playerWhoTriggered)
  someRemoteEvent:FireClient(playerWhoTriggered)
end)

client

someRemoteEvent.OnClientEvent:Connect(function()
  -- toggle the gui here
end)
2 Likes

its saying

2 Likes

It’s because you can’t use “OnClientEvent” in a serverscript, it has to be in a localscript. ^^

2 Likes

nop it doesnt work, idk if i did anything wrong with my code:

game.ReplicatedStorage.DoorOpen.OnClientEvent:Connect(function()
	print("yay")
	script.Parent.Visible = true
end)


script.Parent.Triggered:Connect(function(playerWhoTriggered)
	print("ok")
	game.ReplicatedStorage.DoorOpen:FireClient(playerWhoTriggered)
end)
2 Likes

Where is the client/first script located?

2 Likes

- fire remote event
image - open gui

2 Likes

The script inside the first image needs to be a normal script.

This should solve your problem.

2 Likes

Okay, I made a script which will instead of having a script inside of each individual door loop through your DoorsFolder in workspace (if you have one, if not then it’s better to just make one).

This will fire once the player loads in and everytime a new child is added to your DoorsFolder. You can put this in a LocalScript in StarterPlayerScripts.

local Player = game.Players.LocalPlayer
local DoorsFolder = workspace:FindFirstChild("DoorsFolder")
local Debounce = false

repeat task.wait() until Player.Character

function DoorProximityPromptFunction()
	for _,DoorProximityPrompt in DoorsFolder:GetDescendants() do
		if DoorProximityPrompt:IsA("ProximityPrompt") then
			DoorProximityPrompt.Triggered:Connect(function()
				if not Debounce then
					Debounce = true
					if DoorProximityPrompt.ActionText == "Open" then
						DoorProximityPrompt.ActionText = "Close"
						game.Players.LocalPlayer.PlayerGui.ScreenGui["Door Menu"].Visible = true
					else
						DoorProximityPrompt.ActionText = "Open"
						game.Players.LocalPlayer.PlayerGui.ScreenGui["Door Menu"].Visible = false
					end
					task.wait()
					Debounce = false
				end
			end)
		end
	end
end

DoorProximityPromptFunction()

DoorsFolder.ChildAdded:Connect(function()
	DoorProximityPromptFunction()
end)

This will not only open GUI but will also change ActionText between Open and Close, you can change this however you want.

2 Likes

after using the proximity prompt the prints dont print anything.

2 Likes

Is it the correct folder name?

2 Likes

It’s supposed to be OnClientEvent, and FireClient()

2 Likes