Sliding door using attributes from both player and the door's model

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:
b03079bb19badde58e04c3473fbb6dfe

The door:
d48472dd254327b58ec5eb17f14f2f6b

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?

1 Like

Proximity prompt passes a parameter player.

You can use this parameter to get the individual player instead of the current script which gets the attribute from Players service.

Thank you, your advice worked. ^^

1 Like

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