Simple Door Tutorial

This is my first post! I hope it will be useful to beginners

  1. Making the door
    Make a door in a workspace and name it ‘DoorPart’
    Then anchor it

  2. Scripting the Door
    I know the scripts look complex but it is very simple let’s follow me along!

First lets make a reference to the ‘DoorPart’ we’ve created earlier

local door = workspace:WaitForChild("DoorPart")

Now lets create a ClickDetector

local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = door

Now what is going on first we’ve created clickDetector and set it’s parent to the DoorPart. That’s it!
ok
But it doesn’t do anything so let’s make it functional !

first lets create a ‘Switch’ don’t worry it’s just a variable

local debounce = false
clickDetector.MouseClick:Connect(function()
    if debounce == false then
          door.CanCollide = false
          door.Transparency = 0.5
          debounce = true
    elseif debounce == true then
          door.CanCollide = true
          door.Transparency = 0
          debounce = false
    end
end)

And that’s it! The door should be working now ! If not make sure you did everything like me in this guide

5 Likes

Instead of switching the debounce(switch) in if statements, you can do debounce = not debounce — it will basically do the same thing but in one line then just check if the debounce is true or false, also instead of bool == true, you can do bool, or bool == false you can do not bool

So…

bool == false can be not bool
bool == true can be bool

debounce = not debounce just does the same thing like in the if statements

I know but I prefer using debounce but thanks now I know 100% how to use not debounce and other things Thanks!