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,

Now we want to insert a click detector inside of it, this will act as the clicker.

Great! Now inside of ReplicatedStorage, insert a tool and name it “RedKey”.

Duplicate your part, aka Key1 and put it inside of RedKey, and call it handle,
Perfect! Insert a Local Script inside of StarterPlayerScripts,

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.

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!