Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make the keycard close the door?

So I need help on how to make the keycard close the door too instead of waiting for the door to close itself? It's for a game I am making.

Here is the script I used, this is a script that I found online since I am not a pro in scripting.

	script.Parent.Touched:Connect(function(hit)
	if hit.Parent == "Keycard" then
	script.Parent.Transparency = 0.5
	script.Parent.CanCollide = false
	wait(2)
	script.Parent.Transparency = 1
	script.Parent.CanCollide = true
	end
	end)

2 comments

0

So if this script is in the door area. I believe hit is the object it’s touching so the keycard would be hit. So just say hit.Name == “Keycard” then. If hit.Parent is the keycard and I’m dumb, then say hit.Parent.Name == “KeyCard”. If that solved it please tell me lol.

0

Okay thanks! Let me go try that, but what about the time though? Should I remove the "wait()" ??

2 answers

This sounds like it simply needs the if statement to add an elseif and a boolean variable

local open = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent == "Keycard" and open == false then
script.Parent.Transparency = 0.5
script.Parent.CanCollide = false
open = true
elseif hit.Parent == "Keycard" and open == true then
script.Parent.Transparency = 1
script.Parent.CanCollide = true
open = false
end
end)

2 comments

0

Thank you so much for your answer! :D

0

Hm, it doesn't work..

I haven't tested this yet but it may work

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Keycard" then
		script.Parent.CanCollide = not script.Parent.CanCollide

		if script.Parent.CanCollide then
			script.Parent.Transparency = 1
		else
			script.Parent.Transparency = .5
		end
	end
end)

2 comments

0

Thanks for you answer! But the script doesn't work, when I used the keycard to open the door, the door disappears suddenly.

0

Yeah that actually does work then. In this script he set the transparency to 1 which is invisible. You can play around with transparency on your own if you want it to slowly turn invisible or turn slightly visible.

This discussion is preserved as it was. New answers, comments, and votes are closed.