How do I detect who triggered a ProximityPrompt?

I want to make a door open based on whether a player has a keycard in their inventory. However, even when I take the card out of the players inventory, they are still able to open the door. Here is what I have used:

reader2.ProximityPrompt.Triggered:Connect(function(player)
	for k,n in pairs(player.Backpack:GetChildren()) do
		if n:FindFirstChild("Keycard") then
			granted:Play()
			openclose()
		else
			denied:Play()
		end
	end
end)

I think that the issue may be with function(player), but I’m not sure.

If you know, please help. Thanks!! :grinning:

Is the player getting any errors?

1 Like

is this a local script or a server script

2 Likes

Try removing the Keycard object on the server, instead of the client

How do you mean? It is a server script, and the keycard object has to be inside the backpack.

You said you are removing the Keycard from the player’s backpack, make sure you are removing the Keycard on the Server, not the Client

reader2.ProximityPrompt.Triggered:Connect(function(player)
	if player.Backpack:FindFirstChild("Keycard") then
		granted:Play()
		openclose()
	else
		denied:Play()
	end
end)

You were iterating through the backpack table and looking inside children of the backpack. You should be looking in the Backpack.

Alright, I’ll see if that helps

Tried it, didn’t work. The player was still able to open the door, even without it.

Why are you looping through the items in the backpack and then finding a child inside the tool?

Just do

if player.Backpack:FindFirstChild("Keycard") or player.Character:FindFirstChild("Keycard") then

No need for any loops