Issues with a card activated door

Currently I’m having issues with a door not activating.

Basically I want the script to detect if the card ‘Room 000’ (000 being the room number obviously) has been held up to the door. I feel as my script is correct but isn’t activating as I feel it should.

Heres the script:

local RoomTool = game:GetService('ReplicatedStorage'):WaitForChild('WC_Assets'):WaitForChild('Room'):Clone()

RoomTool.Name = 'Room '..script.Parent:WaitForChild('Configuration'):WaitForChild('RoomNumber').Value
RoomTool.Parent = game:GetService('ReplicatedStorage'):WaitForChild('WC_Rooms')

local db = false
script.Parent.DoorMain.Touched:Connect(function(plr)
	if db == false then
		db = true
	if plr.Parent:FindFirstChild('Room '..script.Parent:WaitForChild('Configuration'):WaitForChild('RoomNumber').Value) ~= nil then
		script.Parent.DoorMain.Transparency = 1
		script.Parent.DoorMain.CanCollide = false
		wait(1)
		script.Parent.DoorMain.Transparency = 0
		script.Parent.DoorMain.CanCollide = true
	else
		print(plr.Parent.Name)
	end
	db = false
	end
end)

Thanks!

The:

	else
		print(plr.Parent.Name)
	end

-part of the script is saying my characters appearance items.

1 Like

Sorry, I’m confused. This is a door card reader that’s supposed to detect when a card touches the reader? But your character appearance objects are getting detected?

1 Like

Yes, exactly.

It should instead detect the name of the card I am holding out… except every way I’ve tried doing it it kind of “refuses” to detect.

Can you send a photo of the card tool in the explorer so I can see what the contents are? It’s kinda hard to visualize the issue with the current information you’ve provided.

Edit:
My best guess is you need to filter the objects that get detected.
if plr.Parent.Name == "ExpectedParentName" then

2 Likes

image Here you go. The script I mentioned above is in ‘DoorHandler’ and the ‘Room’ tool gets replicated to a different folder which will soon be sent to the player via a chat command.

The room tool also gets the name changed and I’ve tried what you’ve mentioned. ;/

From looking at your script I think the reason that only appearance items are being detected is due to the second if statement in your function. You are checking if the parent of the part contains the room key rather than if the parent of the part is the room key. You’d most likely want to check if the parent of the part’s Name instead of using FindFirstChild.

2 Likes

Would I have to detect ‘Handle’ or ‘Room’? I need to detect ‘Room’ as I dont random players barging into others rooms.

Handle is what gets detected

if Handle.Parent.Name == "Room000" then
    --code to open door
end
1 Like

Thanks, I’ll try this. :slight_smile:

1 Like

A model or tool doesn’t have a physical object in the world. The Handle does so it is what will be detected but only if it touches the door.

2 Likes

Does the card name get changed to let’s say “Room000” ?

2 Likes

Mhm, it gets changed to whatever value is in the ‘RoomNumber’ value inside the Configuration folder.

1 Like
if Handle.Parent.Name == "Room"..script.Parent.Configuration.RoomNumber.Value then
    --code to open door
end
2 Likes

How would I be accessing the Handle?

1 Like

Whenever the card touches the detector, the handle will be plr since thats what you’ve named it in your function

2 Likes
local db = false
script.Parent.DoorMain.Touched:Connect(function(handle)
	if db == false then
		db = true
	if handle.Parent.Name == 'Room '..script.Parent.Configuration.RoomNumber.Value then
		script.Parent.DoorMain.Transparency = 1
		script.Parent.DoorMain.CanCollide = false
		wait(1)
		script.Parent.DoorMain.Transparency = 0
		script.Parent.DoorMain.CanCollide = true
	else
		print(handle.Parent.Name)
	end
	db = false
	end
end)

Doesn’t work? I believe I’m following the steps correctly…?

It instead starts printing my avatars appearance… again.

1 Like

Hmm, lemme debug this. Give me a minute

2 Likes

I did a brief change, and removed parent from if Handle.Parent.Name and it printed handle, but no avatar appearance, besides my uppertorso, etc.

Then changed it back and it cannot see my cards name anywhere?

1 Like
local db = false
script.Parent.DoorMain.Touched:Connect(function(handle)
	if db == false then
		db = true
		if handle.Parent.Name == 'Card'.. script.Parent.Configuration.RoomNumber.Value then
			script.Parent.DoorMain.Transparency = 1
			script.Parent.DoorMain.CanCollide = false
			wait(1)
			script.Parent.DoorMain.Transparency = 0
			script.Parent.DoorMain.CanCollide = true
		else
			print("Wrong card")
		end
	db = false
	end
end)

This code seemed to work for me, it’s edited a bit

Edit: I updated the code to work for your door

2 Likes

Didnt… Work… Do you think its because of the space between ‘Room 000’?