Keycard script not working

So, I have a code that checks if my tool touches my mesh object and it doesn’t seem to be working. I attempted to add some outputs to see if it gets an error, but still nothing logs in output. I will provide my code below in order for you to help assist me with this problem.

local KeycardHolder = script.Parent
local KeycardStatus = script.Parent.Parent.KeycardHolderStatus
local DoorPart = game.Workspace.Map.Door7
local TweenService = game:GetService("TweenService")
local OpenDoor = TweenService:Create(DoorPart, TweenInfo.new(3), {Position = Vector3.new(-36.938, 38.089, -66.858)})
local CloseDoor = TweenService:Create(DoorPart, TweenInfo.new(3), {Position = Vector3.new(-36.938, 23.007, -66.858)})
local OpenNoise  = DoorPart["Open/CloseNoise"]

KeycardHolder.Touched:Connect(function(hit)
	if hit.Parent.Name == "Clearance I" then
		print("Success!")
		OpenDoor:Play()
		OpenNoise:Play()
		wait(5)
		CloseDoor:Play()
		OpenNoise:Play()
	else
		print("Failure!")
	end
end)
1 Like

What is KeycardHolder? I don’t see a KeycardHolder variable in there. Please also show me your output.

The keycard holder is a variable for the actual object that is being touched to activate the event. There is also nothing that is logged into the output.

I don’t see it in your script.

What do you mean by this? I do not understand.

Oh, I just realized I didn’t format that part in. I edited the post.

In your script, you did not define the variable KeycardHolder.

I just edited the post. Check it now.

What is the KeycardHolder variable? Is it a tool? If it’s a tool then your Touched event will never fire because tools don’t collide with anything, their Handles do.

Can you show me where this script is located in the Explorer? And see if this is a local script or server script?

It’s strange that your code doesn’t print anything, because if it does not touch the card, it should at least print “Failure!”.

The keycard holder is the actual object that is being touched. The tool that is touching the object is under this part.

if hit.Parent.Name == "Clearance I" then

It is a script inside of the keycard holder.

Please attach a screenshot of the script, in the Explorer.

I included some of the explorer for you.

I see. Are you sure the Keycard’s CanTouch property is set to true?

I already checked that, it is set to true.

Are you sure you’ve touched the keycard with the KeycardHolder part? And are you sure that the KeycardHolder is anchored?

It is 100 percent anchored already. Just checked that.

That’s very strange because it’s working for me

Could it be because I am using a mesh part?