Using this simple table + script to change the positioning of a part if you have a specific tool name.
Could someone assist me in making it work with proximity prompts.
So currently you have to touch a part with a tool that has a specific name to open but I want to make it so you just have to have it in your backpack and then use a proximity prompt to open it.
ProximityPrompt.Triggered:Connect(function(Player)
if Player.Backpack:FindFirstChild("Clearance") or Player.Character:FindFirstChild("Clearance") then
-- Script
end
end)
local door = script.Parent
local bool = true
local bool2 = true
local clearance = {
["Card-Patient"] = false,
["Card-L0"] = false,
["Card-L1"] = false,
["Card-L2"] = false,
["Card-L3"] = false,
["Card-L4"] = true,
["Card-L5"] = true,
["Card-Hostiles"] = true,
["Card-Combative"] = true,
["Card-High Command"] = true,
["Card-Intelligence Agency"] = true,
["Card-Gamepass"] = true
}
function openDoor()
script.Parent.DoorOpen:play()
for i = 1,(door.Size.z / 0.30) do
door.CFrame = door.CFrame - (door.CFrame.lookVector * 0.30)
wait()
end
door.Transparency = 1
for i,v in pairs(door:GetChildren()) do
if v:IsA("Decal") then
v.Transparency = 1
end
end
wait(3)
door.Transparency = 0
for i,v in pairs(door:GetChildren()) do
if v:IsA("Decal") then
v.Transparency = 0
end
end
script.Parent.DoorClose:play()
for i = 1,(door.Size.z / 0.30) do
wait()
door.CFrame = door.CFrame + (door.CFrame.lookVector * 0.30)
end
end
local ProximityPrompt = script.Parent.Parent.KeycardReader1.ProximityPrompt
ProximityPrompt.Triggered:Connect(function(Player)
if Player.Backpack:FindFirstChild("Clearance") or Player.Character:FindFirstChild("Clearance") then
if Player.Name == "Handle" and clearance[Player.Parent.Name] and bool then
bool = false
script.Parent.AccessGranted:play()
script.Parent.Parent.Light1.brickColor = BrickColor.new("Lime green")
script.Parent.Parent.Light2.brickColor = BrickColor.new("Lime green")
script.Parent.Parent.Light3.brickColor = BrickColor.new("Lime green")
openDoor()
wait(1)
script.Parent.Parent.Light1.brickColor = BrickColor.new("Lily white")
script.Parent.Parent.Light2.brickColor = BrickColor.new("Lily white")
script.Parent.Parent.Light3.brickColor = BrickColor.new("Lily white")
bool = true
elseif Player.Name == "Handle" and not clearance[Player.Parent.Name] and bool2 then
bool2 = false
script.Parent.AccessDenied:play()
wait(1)
bool2 = true
end
end
end)
local ProximityPrompt = script.Parent.Parent.KeycardReader2.ProximityPrompt
ProximityPrompt.Triggered:Connect(function(Player)
if Player.Backpack:FindFirstChild("Clearance") or Player.Character:FindFirstChild("Clearance") then
if Player.Name == "Handle" and clearance[Player.Parent.Name] and bool then
bool = false
script.Parent.AccessGranted:play()
script.Parent.Parent.Light1.brickColor = BrickColor.new("Lime green")
script.Parent.Parent.Light2.brickColor = BrickColor.new("Lime green")
script.Parent.Parent.Light3.brickColor = BrickColor.new("Lime green")
openDoor()
wait(1)
script.Parent.Parent.Light1.brickColor = BrickColor.new("Lily white")
script.Parent.Parent.Light2.brickColor = BrickColor.new("Lily white")
script.Parent.Parent.Light3.brickColor = BrickColor.new("Lily white")
bool = true
elseif Player.Name == "Handle" and not clearance[Player.Parent.Name] and bool2 then
bool2 = false
script.Parent.AccessDenied:play()
wait(1)
bool2 = true
end
end
end)
Assuming you meant that ^
It doesn’t work, no errors given.
local door = script.Parent
local doormodel = script.Parent.Parent
local debounce = false
local bool = true
local bool2 = true
local plrs = game:GetService("Players")
local clearance = {
["Card-Patient"] = false,
["Card-L0"] = false,
["Card-L1"] = false,
["Card-L2"] = false,
["Card-L3"] = false,
["Card-L4"] = true,
["Card-L5"] = true,
["Card-Hostiles"] = true,
["Card-Combative"] = true,
["Card-High Command"] = true,
["Card-Intelligence Agency"] = true
}
local function openDoor()
door.DoorOpen:play()
for i = 1, (door.Size.Z / 0.30) do
door.CFrame -= (door.CFrame.lookVector * 0.30)
task.wait()
end
door.Transparency = 1
for i,v in pairs(door:GetChildren()) do
if v:IsA("Decal") then
v.Transparency = 1
end
end
task.wait(3)
door.Transparency = 0
for i,v in pairs(door:GetChildren()) do
if v:IsA("Decal") then
v.Transparency = 0
end
end
door.DoorClose:play()
for i = 1, (door.Size.Z / 0.30) do
task.wait()
door.CFrame += (door.CFrame.lookVector * 0.30)
end
end
local function checkAccess(touch)
if debounce then
return
end
if touch.Parent:FindFirstChild("Humanoid") then
debounce = true
local char = touch.Parent
local plr = plrs:GetPlayerFromCharacter(char)
local bp = plr.Backpack
local access = false
for item, bool in pairs(clearance) do
if bp:FindFirstChild(item) or char:FindFirstChild(item) then
if bool then
access = true
end
end
end
if access then
bool = false
door.AccessGranted:play()
doormodel.Light1.BrickColor = BrickColor.new("Lime green")
doormodel.Light2.BrickColor = BrickColor.new("Lime green")
doormodel.Light3.BrickColor = BrickColor.new("Lime green")
openDoor()
task.wait(1)
doormodel.Light1.BrickColor = BrickColor.new("Lily white")
doormodel.Light2.BrickColor = BrickColor.new("Lily white")
doormodel.Light3.BrickColor = BrickColor.new("Lily white")
bool = true
elseif not access then
bool2 = false
door.AccessDenied:play()
task.wait(1)
bool2 = true
end
end
task.wait(3)
debounce = false
end
doormodel.KeycardReader1.Touched:Connect(checkAccess)
doormodel.KeycardReader2.Touched:Connect(checkAccess)
This works with your current setup (Touched event), when a player comes into contact with the card reader of the door the script will check the player’s backpack for a valid tool which would give them clearance to access the room, if the tool is found but its associated value in the clearance table is false then the tool is rejected and access isn’t granted.
local door = script.Parent
local doormodel = script.Parent.Parent
local debounce = false
local bool = true
local bool2 = true
local clearance = {
["Card-Patient"] = false,
["Card-L0"] = false,
["Card-L1"] = false,
["Card-L2"] = false,
["Card-L3"] = false,
["Card-L4"] = true,
["Card-L5"] = true,
["Card-Hostiles"] = true,
["Card-Combative"] = true,
["Card-High Command"] = true,
["Card-Intelligence Agency"] = true
}
local function openDoor()
door.DoorOpen:play()
for i = 1, (door.Size.Z / 0.30) do
door.CFrame -= (door.CFrame.lookVector * 0.30)
task.wait()
end
door.Transparency = 1
for i,v in pairs(door:GetChildren()) do
if v:IsA("Decal") then
v.Transparency = 1
end
end
task.wait(3)
door.Transparency = 0
for i,v in pairs(door:GetChildren()) do
if v:IsA("Decal") then
v.Transparency = 0
end
end
door.DoorClose:play()
for i = 1, (door.Size.Z / 0.30) do
task.wait()
door.CFrame += (door.CFrame.lookVector * 0.30)
end
end
local function checkAccess(plr)
if debounce then
return
end
if plr then
debounce = true
local char = plr.Character
local bp = plr.Backpack
local access = false
for item, bool in pairs(clearance) do
if bp:FindFirstChild(item) or char:FindFirstChild(item) then
if bool then
access = true
end
end
end
if access then
bool = false
door.AccessGranted:play()
doormodel.Light1.BrickColor = BrickColor.new("Lime green")
doormodel.Light2.BrickColor = BrickColor.new("Lime green")
doormodel.Light3.BrickColor = BrickColor.new("Lime green")
openDoor()
task.wait(1)
doormodel.Light1.BrickColor = BrickColor.new("Lily white")
doormodel.Light2.BrickColor = BrickColor.new("Lily white")
doormodel.Light3.BrickColor = BrickColor.new("Lily white")
bool = true
elseif not access then
bool2 = false
door.AccessDenied:play()
task.wait(1)
bool2 = true
end
end
task.wait(3)
debounce = false
end
doormodel.KeycardReader1.ProximityPrompt.Triggered:Connect(checkAccess)
doormodel.KeycardReader2.ProximityPrompt.Triggered:Connect(checkAccess)
Here’s a similar version which works for ProximityPrompt instances instead, you’ll need a prompt inside each card reader. I’ve also made some other slight optimisations like replacing deprecated methods with their contemporary versions. Don’t forget that properties should be capitalised in the way I have done in the 2 provided scripts. I’ve also swapped wait for task.wait() for accurancy/reliability purposes. Both Triggered/Touched events use the same callback function so we can connect the function by name as opposed to copying and pasting the same code into each Touched/Triggered event. Also when performing arithmetic operations “x = x - y” is the same as “x -= y”, the difference is only a syntactic one.
Hey, I was experimenting and I noticed one of two things; The doors have a really long and obnoxious cooldown and if I move someones humanoidrootpart (teleporting them like that) it breaks the doors. Any idea why?
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart") then
hit.Parent.HumanoidRootPart.Position = script.Parent.Parent.Teleport2.Position
end
end)
It makes the doors stop working entirely for the local player unless killed/reset.