Keycard Door Tutorial

How to make a keycard door work.

by Varis_Marcell

Author Avatar

Tutorial Outline

~ Setup --Required to complete for tutorial. (Basic)

 ~ Sensor Script --Required to complete for tutorial. (Basic)

 ~ KeyCard Giver --Required to complete for extended tutorial. (Extended Edition)
 ~ More Information --Required to complete if you want to create multiple different keycards and doors.
 ~ Credits


First, create your door frame however you like. Next, create your door, and

name it 'Door'. (Ignore the ' ' when typing the name.) After completing this,

create another part which will detect the keycard touching it. Name this part

'Sensor'. For the next step, create a tool object, insert the part you want

the keycard to look like, and name the part 'Handle'. Add a Humanoid object

to the Handle part and rename it 'Real'. Finally, drag the tool into the

StarterPack folder in the Explorer tab. Now you are ready to start coding your

door sensor!

Sensor Script

Create a script, and drag it into the sensor part. Then copy this code into

your script.

local function OnCardTouch(Hit)
    local Real = Hit:FindFirstChild("Real")
    if Real then
	    -- I decided to make the door transparent, but you could run an animation.
        script.Parent.Parent.Door.Transparency = 0.5
        script.Parent.Parent.Door.CanCollide = false
        wait(2) -- This number is how long, in seconds, the door will stay open.
        script.Parent.Parent.Door.Transparency = 0
        script.Parent.Parent.Door.CanCollide = true


Now that you have a door, a keycard, and a sensor, you have completed the

basic tutorial. If you would like to make a keycard tool giver, continue

reading. Otherwise, if you are fine with everyone getting a keycard, you

finished the tutorial!

KeyCard Giver

The KeyCard giver is a part which a player clicks to recieve a KeyCard, similar

to the tools you can click to get in Jailbreak or other games. Make a part which

the player will click either identical to the KeyCard, or whatever you want the

giver to look like. Insert a ClickDetector object into the giver part, then create

a script object in the same part. Inside the script, insert the following code

for the tool giver to work.


Make sure to name the KeyCard tool 'KeyCard' and drag it into the ServerStorage

folder from the StarterPack folder.

local KeyCard = "KeyCard"

    -- Here I implement a check to see if the player already has the card.
    if not player.Backpack:FindFIrstChild(KeyCard) then
        game.ServerStorage.KeyCard:Clone().Parent = player.Backpack

More Information

Now that you have created one keycard door and giver, why not make more different

keycards that will open different doors! To do this, duplicate the keycard tool,

door (everything, the frame, the sensor, and the actual door), and the giver.

Next, rename the humanoid in the tool, and change where indicated in the script.

For example, you rename the humanoid 'Stuff'. Also, rename the Door part something else,

for example, 'Door2'.


Remember to rename the KeyCard tool something else such as 'KeyCard2'.

local function OnCardTouch(hit)
    local Real = Hit:FindFirstChild("Stuff") --Rename the inside of the parentheses "Stuff".
    if Real then
        script.Parent.Parent.Door2.Transparency = 0.5 --Rename the Parent.Door  Parent.Door2
        script.Parent.Parent.Door2.CanCollide = false
        script.Parent.Parent.Door2.Transparency = 0
        script.Parent.Parent.Door2.CanCollide = true


Now, for the other giver, nothing needs to be renamed, only changes to the script need to be made.

local KeyCard = "KeyCard2"

	if not player.Backpack:FindFirstChild(KeyCard2) then
		game.ServerStorage.KeyCard:Clone().Parent = player.Backpack

This process can be repeated multiple times, ensuring that you will never run out

of variations for your KeyCard doors!    


~Thank you to the creators of this game for providing the platform to create this tutorial.

~My Discord is Varis_Marcell#7616 if something does not work.

Tutorial created by Varis_Marcell on February 5, 2018

Revised on February 7, 2023

View in-game to comment, award, and more!