Trigger ProximityPrompt with tool equipped issue

Player should open door with ProximityPrompt only with tool equipped.
It works but door opens when player equips keycard after triggering without equipped tool.

function active()
	if idle and not locked then
		idle = false
	    if not isopen then
		openSound:Play()
			leftdooropentween:Play()
			rightdooropentween:Play()
			isopen = true
     	else
		closeSound:Play()
		idle = false
			leftdoorclosetween:Play()
			rightdoorclosetween:Play()
			isopen = false
	end
	wait(1,3)
	idle = true
	end
end


proximityprompt2.Triggered:Connect(function(player)
	button2.ButtonPress:Play()
	local char = player.Character
	if char:WaitForChild("Level 1 Keycard") then
	active()
	end
end)	

proximityprompt1.Triggered:Connect(function(player)
	button1.ButtonPress:Play()
	local char = player.Character
	if char:WaitForChild("Level 1 Keycard") then
		active()
	end
end)

Hi, the issue resides within your proximity prompts triggered event, you are using WaitForChild to check for the keycard, which will no matter what wait for the keycard to be spawned inside of the character, or it will be timed out and yield a warning. This is a really easy fix, instead of waiting for the child, you can use FindFirstChild, which will return true if the keycard is inside the character, and false in the opposite case.

Here is the code for better understanding:

proximityprompt2.Triggered:Connect(function(player)
	button2.ButtonPress:Play()
	local char = player.Character
	if char:FindFirstChild("Level 1 Keycard") then
		active()
	end
end)	

proximityprompt1.Triggered:Connect(function(player)
	button1.ButtonPress:Play()
	local char = player.Character
	if char:FindFirstChild("Level 1 Keycard") then
		active()
	end
end)

Let me know if the code still doesnt work, i havent tested it since it was an easy fix.

2 Likes

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