What I want to achieve is: By using attribute on the player, open the sliding door by checking the value of the attribute on the door If it state “Granted”.
For example:
- Attribute of the player: “Access”, “Level1”
- Attribute of the door: “Level1”, “Granted”
The script won’t work from a certain point when running.
The attribute on the player:
The door:
Here the script I am trying to fix (Server Script)
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
AccessGranted = false
function OpenDoor(door)
-- No error when running, no need to fix here
end
function CloseDoor(door)
-- No error when running, no need to fix here
end
function DeniedAccess(door)
-- No error when running, no need to fix here
end
-- The script stopped working from this point
for _, door in pairs(CollectionService:GetTagged("SlidingKeycardDoorT1B")) do -- Door's tag
local Sweep = door.Parent.ControlA.SweepHandle.CardSweep.Attachment.ProximityPrompt
local Sweep2 = door.Parent.ControlB.SweepHandle.CardSweep.Attachment.ProximityPrompt
local playerAttribute = Players:GetAttribute("PrimaryAccess")
local playerAttribute2 = Players:GetAttribute("SecondaryAccess")
local DoorAttribute = door:GetAttribute(playerAttribute)
local AccessCheck = door:GetAttributes(DoorAttribute)
Sweep.Triggered:Connect(function()
print("Door triggered, functioning")
Sweep.Enable = false
Sweep2.Enable = false
if AccessCheck == "Granted" then
AccessGranted = true
OpenDoor(door)
wait(3)
CloseDoor(door)
else
DeniedAccess(door)
end
Sweep.Enable = true
Sweep2.Enable = true
end)
Sweep2.Triggered:Connect(function()
print("Door triggered, functioning")
Sweep.Enable = false
Sweep2.Enable = false
if AccessCheck == "Granted" then
AccessGranted = true
OpenDoor(door)
wait(3)
CloseDoor(door)
else
DeniedAccess(door)
end
Sweep.Enable = true
Sweep2.Enable = true
end)
end
What do I do to fix any parts of the script that cause the script to stop working?