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

How do I make a keycard door like in SCP?

I've seen other tutorials, but they only show double doors or are unreliable.

I have my doors and keycards, I just need to know what to do.

2 answers

✓ Accepted answer

##Concept

Due to Scripting Helpers' policy on questions which do not contain code or show accurate attempt at making such code, I will only provide pseudo code for this answer. You can find more details as to what is considered a good question here.

Essentially, what you will want to do is to have a tool and door, which you have explained you already have. You'll want to give your door a unique name for the script to identify and allow the user through. You'll also want to give your keycard a unique name so that the script will be able to identify it and activate the door.

Once both of those are completed, we can go ahead and insert the script into the part which will be accepting the keycard. You'll want to look into the Touched event, it's an event for every BasePart. This activates whenever any part touches the one the event is set on. When the KeyCard touches the accepting part, the script will need to confirm it is actually a keycard touching and not simply a hand. Generally, the main thing being held in a tool is called the "Handle" which isn't a unique identifier for the tool. However, if you named the tool "Keycard" or something like that then we can get the Parent of the Handle, then find the name of that parent.

While the event is running, you do not want someone coming along and messing up the open/close times. To avoid this, you can use something commonly called a debounce. Which is generally a variable held outside the event and is true/false whenever you set it so at the beginning and at the end of the script.

One more thing that might be good to check. See if the tool is actually being held by a player/character. All characters have a object in them called "Humanoid" which is generally a good indicator.

Once again, due to site policies on questions not containing code, this will simply be pseudo code.

--[[
Set a variable which will tell the script if the event is already running or not, ex. active = false
It's recommended to set a variable which will be the door. ex. d = .door
Connect a function to the AcceptorPart.Touched event. ex. .Touched:Connect(function(partWhichHit)
	If the event isn't already running AND the partWhichHit's parent has the specified name AND the parent of the parent to partWhichHit has a humanoid in it...
		set the event is already running
		indicate that the door is open and passable
		wait a few seconds
		indicate that the door is closed and not passable
		set the variable which the event is not running
	End the if statement.
End and close the function and Connect statement.
]]--

If everything went right, it should look something like this. Imgur

1 comment

0

Stop spamming on the site mega

1). well you could just make a tool and name it keycard, give it a handle too, put the tool in starter pack

2).then put a brick in front of the door which requires a key card

write the following code:

local part = workspace.etc.etc -- change this to the directory of the part that is touched to open the door for players with keycards
part.Tocuhed:connect(function(hit)
	local char = hit.Parent
	if char:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(char)
		if player then
			if player.Backpack:FindFirstChild("Keycard") then
				part.CanCollide = false
				wait(0.2)
				part.CanCollide = true
			end
		end
	end
end)

so the above code just listens for when the part stored in the variable part is touched then declares the variable char to give us access to the parent of the part that touched the door; it then checks if the parent of the part is a player's character, if so then it checks whether or not the player has a keycard in their backpack; if they have a key card then the part stored in the variable part becomes "un-collidable", it waits 0.2 seconds then it becomes collidable again

however, you can do the code differently to suit what your looking for

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