How To Make Piggy Style Doors - Part 1

Hello and welcome to part 1 on my How To Make Piggy Style Doors Basic tutorials.
We will cover how you can set up Tool Specific Doors that only let you enter if you have a certain tool in your inventory.

Let’s begin.

First, create your part. It can be like anything, but to keep it simple I am going to use a regular part.


Now since we are going for the piggy style, we want it to be colour coded. So make it red for example.

We want to call it Key1 or anything memorable. Like so,Screenshot (28)
Now we want to insert a click detector inside of it, this will act as the clicker.
Screenshot (30)
Great! Now inside of ReplicatedStorage, insert a tool and name it “RedKey”.
Screenshot (32)
Duplicate your part, aka Key1 and put it inside of RedKey, and call it handle,


Perfect! Insert a Local Script inside of StarterPlayerScripts,
Screenshot (35)
Now we can begin scripting, so follow my lead!

local red_key = game.Workspace.Key1 -- Defining the part

red_key.ClickDetector.MouseClick:Connect(function(playerWhoClicks) -- The player who clicks the key
local red_tool = game.ReplicatedStorage.RedKey:Clone() -- Cloning it
red_tool.Parent = playerWhoClicks.Backpack -- Putting it in their backpack/inventory
red_key:Destroy() -- Destroying the part
end)

The reason we have set the “Two factor key” up is because if the player steps on the tool, they will automatically equip it. We don’t want that.

Ok, now let’s set up the door!
Insert another part into workspace, call it RedDoor and size it to your will.


Make sure it is anchored and Red. Insert a click detector inside the door.
Screenshot (37)
Now inside of your local script, write this:

local red_door = game.Workspace.RedDoor -- Defining the door

red_door.ClickDetector.MouseClick:Connect(function(playerWhoClicked) -- Defining the player who clicks

if playerWhoClicked.Backpack:FindFirstChild("RedKey") then -- Making sure they have the key
red_door:Destroy() --Destroying the door
else

end
end)

And there you go! The doors should now be working!

Here is the complete script:

local red_key = game.Workspace.Key1 -- Defining the part

red_key.ClickDetector.MouseClick:Connect(function(playerWhoClicks) -- The player who clicks the key
local red_tool = game.ReplicatedStorage.RedKey:Clone() -- Cloning it
red_tool.Parent = playerWhoClicks.Backpack -- Putting it in their backpack/inventory
red_key:Destroy() -- Destroying the part
end)

 local red_door = game.Workspace.RedDoor -- Defining the door

red_door.ClickDetector.MouseClick:Connect(function(playerWhoClicked) -- Defining the player who clicks

if playerWhoClicked.Backpack:FindFirstChild("RedKey") then -- Making sure they have the key
red_door:Destroy() --Destroying the door
else

end
end)

Part 2 should be out very soon, and we will cover how to replace tools in your inventory!

If it was helpful, please like this and leave your feedback!

13 Likes

Very good tutorial, but in the next tutorial you could teach people how to tween the door.

1 Like

In piggy the locked doors don’t tween, but the regular doors do!

The first 3 tutorials will be on the locked doors, then regular doors!

Thanks

1 Like

while i’m unable to check atm, Im pretty confident from making something like this a few months back that if a player Is holding the gear it does not show up in their backpack and therefor your door won’t work if it is being held.

1 Like

Yeah.

I am aiming to do Click Detector doors, like Piggy.

But who knows, I might do the Door Touched thing too

1 Like

Click detectors or touched, they both will not find the key if the player is holding it, I would also recommend using Mouse.Target instead of a click detector since click detectors do not function while the a tool is being held.

1 Like

I know.

As I have said, it is like piggy, so they need to unequip the tool to make it function.

1 Like

Or you could just check if the tool is in their character, as that’s where it goes when equipped.

2 Likes

Correct, that is a method of finding the tool.
However, my tutorials will be ClickDetector Based

I know, but just set “Enabled” on the tool to false, and then they can click click detectors while holding the tool.

Edit: Why link this post instead of the top?

1 Like

You say that the doors are ‘Piggy Style’, however the door can only be opened if the player isn’t holding the key…In Piggy, I’m pretty sure you’re able to open things by walking into them with the required item in your hand, as well as clicking on said thing with the item.

Why is there an “else” there? You could just have that one if statement and be done with it. You can also just change that if statement to:

if playerWhoClicked.Backpack:FindFirstChild("RedKey") or playerWhoClicked.Character:FindFirstChild("RedKey") then
    red_door:Destroy()
end

This would allow players to open doors by clicking on them with the key…and all it took was another condition in your if statement.

Edit:
Read through the script again, and the door destroying thing is local. I’m pretty sure that you can use server scripts with click detectors. This would just delete the door for the player who opened it, and since the grabbing of the key is on the server it would stop other players from progressing entirely.

Your script works, but it could be a lot better gameplay wise with a tiny bit more effort.

I have tested this, and it doesn’t seem to be true, however a nice feature for them to add!

Alright, that’s it. A load of people say that, so what Im gonna do is revamp my tutorials in a few days!

Thanks so much for your feedback!

1 Like

Unfortunately this is not a significant resource.