You would want a Script, and you would want to put it in the Door brick, not a model if it is part of a model.
Now let me walk you through it.
The first thing we want to do is create a function to detect when the door is touched, like so:
Now, we want the door to open when somebody touches it who is you, and remain closed when somebody who is not you touches it. Unfortunately, this function will be used any time ANY part hits the door, not necessarily just a person. So, we need to make sure the person touching the door is a person, which can be done like so:
2 | if hit.Parent.Humanoid ~ = nil then |
What the above code does is detect if the parent of the part that hit it (in the case of a Player, the model of the Player that moves in the game, called the Character) has a Humanoid within it, a part that is (usually) only found in Players. Another way to do it would be like so and would not be fooled by Models with Humanoids in them:
2 | if game.Players:GetPlayerFromCharacter(hit.Parent) ~ = nil then |
This simply checks if there is a Player (in Players) whose name is the same as the Parent of the part that hit the door. I, personally, prefer the second method, so I will continue to use it in this tutorial.
The next thing we want to do is make sure the person hitting the door is still alive. Why? If somebody kills you, or you reset, and you touch the door, anybody else will be able to walk through. So, we add a little piece of code that checks whether the Character's Humanoid has a health greater than 0.
2 | if game.Players:GetPlayerFromCharacter(hit.Parent) ~ = nil then |
3 | if hit.Parent.Humanoid.Health > 0 then |
Now that we've done that, we can get to the actual, important piece of the code: opening the door. Here, we want to check the username of the Player (in Players) and make sure that this person who touched your door is you. then we want to open the door. Since I will be using this Player again, I will make him/her into a variable.
02 | if game.Players:GetPlayerFromCharacter(hit.Parent) ~ = nil then |
03 | if hit.Parent.Humanoid.Health > 0 then |
04 | player = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if player.Name = = "iiShadowTheif" then |
06 | script.Parent.Transparency = 0.7 |
07 | script.Parent.CanCollide = false |
And that will make the door open for you! Make sure to put it in the door brick.
If you want to kill the person who touches the door if they're not you, you can add this tiny little piece:
02 | if game.Players:GetPlayerFromCharacter(hit.Parent) ~ = nil then |
03 | if hit.Parent.Humanoid.Health > 0 then |
04 | player = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if player.Name = = "iiShadowTheif" then |
06 | script.Parent.Transparency = 0.7 |
07 | script.Parent.CanCollide = false |
09 | player.Character:BreakJoints() |
BreakJoints() is basically a method that kills a character.
Thanks for reading all of this (if you actually did) and I hope it helped you!
~Kaamchor