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.
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?
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
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.
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.
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