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)