Proximity Door not working

I think I fixed another issue with my script, but now the prox on the door isnt working in my script. I tried changing to touching and etc. no use. The door opens per one person and if you dont have the key then it wont but now it wont open for no one.

here is my script. i think its something with the character…
12.03.2022_11.16.59_REC

.

Is the ProximityPrompt visible? Or does nothing happen when you trigger the ProximityPrompt?

nothing happens after activating the prompt

Can you show me where u have the GreenKey? If you have it in your backpack change:

if plr.character.GreenKey then

to:

plr.Backpack:FindFirstChild("GreenKey") or plr.Backpack:FindFirstChild("GreenKey")

And if that doesn’t works keep the line of code above and change

prox.Triggered:Connect(function(plr)

to

prox.TriggerEnded:Connect(function(plr)

assigning the prox variable to the cloned door should work, i think the proximity prompt you’re using is still in ReplicatedStorage

1 Like

The prox variable is still set to the proximity prompt that’s in ReplicatedStorage, not the door that you cloned into workspace.

local prox = Door.Prox

thank you all so much! im still learning, but with ur guys help I got it too work!

There are a few issues with your code:

  • You aren’t using the ProximityPrompt in the door that you’ve cloned. Instead you’re using the ProximityPrompt in the door in ReplicatedStorage.

  • The way you are checking if the “GreenKey” is under the players character will error if it isn’t there.

  • You are also assuming the players character exists when the prompt is triggered. In most cases the players character should exists but in some rarer cases the players character may not exists. It is good practice to check for the players characrter.

Try this code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local door = ReplicatedStorage.Door10:Clone()
local prox = door.Prox

door.Parent = workspace

prox.Triggered:Connect(function(player)
	local character = player.Character
	
	-- Makes sure the players character exists
	if character ~= nil and character.Parent == workspace then
		-- Checks if the character has a green key
		if character:FindFirstChild("GreenKey") then
			door.Transparency = 0.5
			door.CanCollide = false
			
			-- Better alternative to using wait(n)
			task.wait(1)
			
			door.Transparency = 0
			door.CanCollide = true		
		end
	end
end)

Note: It is better to use task.wait(n) instead of wait(n) as it is more reliable
https://developer.roblox.com/en-us/api-reference/lua-docs/task

thank you too I made some of these corrections already, but you pointed out one I missed. now the script is working more fluently thank youu!!