ProximityPrompt keycard door player problem

Alright so, I am making a door system. Where you need to hold out a keycard and then use the Proximity prompt to open the door. Alright so, if you can see in the script I have a variable called “realplayer”. Now, the realplayer var is set everytime a player gets added. Now, you can see the problem, if 2 people join at the same time, the last person who joined can use the doors. While the first person who joined cannot. I have no idea on how I can fix this. Thanks.

local Door = script.Parent
local Debounce = true
local Debounce2 = true
local worked = false
local realplayer = nil
local Access = {
	["L1"] = true, 
	["L2"] = true, 
	["L3"] = true,
	["L4"] = true,
	["L5"] = true,
}



game.Players.PlayerAdded:Connect(function(player)
	realplayer = player
	print(realplayer)
end)



function openDoor()
	script.Parent.Open:play()
	for i = 1,(Door.Size.z / 0.01) do
		Door.Parent.Slot2.CFrame = Door.Parent.Slot2.CFrame + (Door.CFrame.UpVector * 0.15)
		Door.Parent.Slot1.CFrame = Door.Parent.Slot1.CFrame + (Door.CFrame.UpVector * 0.15)
		Door.Parent.Glass.CFrame = Door.Parent.Glass.CFrame + (Door.CFrame.UpVector * 0.15)
		Door.CFrame = Door.CFrame + (Door.CFrame.UpVector * 0.15)
		wait()
	end
	wait(3)
	script.Parent.Close:play()
	for i = 1,(Door.Size.z / 0.01) do
		wait()
		Door.Parent.Slot2.CFrame = Door.Parent.Slot2.CFrame - (Door.CFrame.UpVector * 0.15)
		Door.Parent.Slot1.CFrame = Door.Parent.Slot1.CFrame - (Door.CFrame.UpVector * 0.15)
		Door.Parent.Glass.CFrame = Door.Parent.Glass.CFrame - (Door.CFrame.UpVector * 0.15)
		Door.CFrame = Door.CFrame - (Door.CFrame.UpVector * 0.15)
	end
end






script.Parent.Parent.Prompt.ProximityPrompt.Triggered:Connect(function()
	--print(1)
	if Debounce then
	--	print(2)
		for i, v in pairs(Access) do
	--		print(3)
			if realplayer.Character:FindFirstChild(i) and v == true then
				worked = true
	--			print(4)
			end
	--		print(5)
		end
	--	print(6)
		if worked == true then
	--		print(7)
			--		print(142314234)
			script.Parent.Parent.Prompt.ProximityPrompt.Enabled = false
			script.Parent.Parent.RemoteEvent:FireClient(realplayer)
	--		print(1235132515231235)
			Debounce = false
			worked = false
			script.Parent.Yes:play()
			script.Parent.Parent.Light.Light1.BrickColor = BrickColor.new("Lime green")
			script.Parent.Parent.Light.Light2.BrickColor = BrickColor.new("Lime green")
			script.Parent.Parent.Light.Light3.BrickColor = BrickColor.new("Lime green")
			script.Parent.Parent.Light.Light4.BrickColor = BrickColor.new("Lime green")
			openDoor()
			wait(1)
			script.Parent.Parent.Light.Light1.BrickColor = BrickColor.new("Institutional white")
			script.Parent.Parent.Light.Light2.BrickColor = BrickColor.new("Institutional white")
			script.Parent.Parent.Light.Light3.BrickColor = BrickColor.new("Institutional white")
			script.Parent.Parent.Light.Light4.BrickColor = BrickColor.new("Institutional white")
			Debounce = true
			script.Parent.Parent.Prompt.ProximityPrompt.Enabled = true
	--		print(8)
		end
	end	
end)
2 Likes

Can’t you use a table to store players instead? That way you could have multiple. You can check it with table.find().

Well, I got a question. If a player was holding a card that had access. And a player is not holding a card, could the player without the card open it still?

Im not quite sure how the system works as I dont see any place in the script that blacklists them if they are not holding a card. If you want them to not have access just use table.remove().

This is for a military game, I want everyone to have access if they have the correct card.

ProximityPrompts pass the player as the sole argument of Triggered. You should be using the player passed in Triggered to know who pressed on the prompt.

It is incredibly important for developers to start getting into the habit of reading documentation on the things they’re using first to see if there’s anything they might be able to find. From there, you might find your own solution, or you can ask better questions such as understanding what the documentation is saying or how to apply the knowledge practically. This applies to both developers asking questions and developers trying to give answers.

2 Likes

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