Heya I am making keycard doors for my headquarters, one is only available to be accessed with one card. And another is only accessed with 2 cards, the last is accessed with 3 cards. The last two don’t/didn’t work becuse originally I tried this:
local model = script.Parent
local detector = model:WaitForChild("Detector")
local center = model:WaitForChild("CenterPiece")
local sound = center:WaitForChild("Sound")
local open = false
detector.Touched:Connect(function(hit)
if hit.Name == "Handle" then
if hit.Parent.Name == "Regular Keycard" then
if hit.Parent.Name == ("Special Keycard") then
if hit.Parent.Name == ("Owner Keycard") then
if not open then
open = true
for i, v in pairs(model:GetDescendants()) do
if v.Parent.Name == "Door" then
v.CanCollide = false
v.Transparency = 1
end
end
center.CanCollide = false
sound.TimePosition = 0.4
sound:Play()
wait(2)
for i, v in pairs(model:GetDescendants()) do
if v.Parent.Name == "Door" then
v.CanCollide = false
if v.Material ~= Enum.Material.Glass then
v.Transparency = 0
else
v.Transparency = 0.5
end
end
end
center.CanCollide = true
open = false
end
end
end
end
end
end)
And realized wait a second, I can’t do it with making 3 names for one keycard, or whatever came in my mind… Then I tried this:
local model = script.Parent
local detector = model:WaitForChild("Detector")
local center = model:WaitForChild("CenterPiece")
local sound = center:WaitForChild("Sound")
local open = false
local tools = {"Regular Keycard", "Special Keycard", "Owner Keycard"}
detector.Touched:Connect(function(hit)
if hit.Name == "Handle" then
if table.find(tools, hit.Parent.Name) then
if open == false then
open = true
for i, v in pairs(model:GetDescendants()) do
if v.Parent.Name == "Door" then
v.CanCollide = false
v.Transparency = 1
end
end
center.CanCollide = false
sound.TimePosition = 0.4
sound:Play()
wait(2)
for i, v in pairs(model:GetDescendants()) do
if v.Parent.Name == "Door" then
v.CanCollide = true
if v.Material ~= Enum.Material.Glass then
v.Transparency = 0
else
v.Transparency = 0.5
end
end
end
center.CanCollide = true
open = false
end
end
end
end)
I used here tables, which fixed the collision issue, yet didn’t allow me to use 3 tools to open the door, only the first one made it open (Regular Keycard) so now I’m confused why none of this worked. If anyone could help me, that would be great!!
Screenshot of where the tools are, and what their names are:
