How To Make An Animated Door (Click To Open)

Hello everyone! As of January 2021, attributes have been released to beta users and will be released to all users very soon.

With this, we’re not entirely sure what will happen to the value objects themselves. They may be removed, or they may stay (although, with attributes being released there’s not really a point of keeping them unless attributes don’t cover everything that the value objects do).

Therefore, in case value objects are removed and this tutorial becomes outdated, this reply will be showing you how to edit your door model so that it uses attributes to replace the BoolValue.


For this, I will simply be using the door model that I have prepared already.

Let’s start by going back to the children in the explorer tab:

First, delete the BoolValue (which is named Opened) if it still exists at the time of you reading this.

Then, click on your model (the icon with the three colored bricks). In the properties tab, you’ll want to click on “Add Attribute”

That should bring up this menu:
Screenshot (9)

For the name, you’ll want to name it whatever the BoolValue was named before. If you’re using my door model, the name should be “Opened.”

For the type, open the dropdown menu (by click on “string”) and select “boolean.” Then hit “Save” and you should see something like this in the properties tab:
Screenshot (11)

Keep the box next to the attribute unchecked, just like the BoolValue was before.


Editing The Script

I have realized that the way I “taught” you the script wasn’t very efficient. Especially because my teaching method was:

This was my first tutorial and therefore I have realized there’s a lot of areas to improve in.

I will get into more detail about what this script is after I show you what to edit.

You can find the script in the part called “DoorPart.”

When you double click on the script, this is what you’ll see:

local frame = script.Parent
local clickDetector = frame:WaitForChild("ClickDetector")
local model = frame.Parent
local Close = model:WaitForChild("DoorClose")
local Open = model:WaitForChild("DoorOpen")
local opened = model:WaitForChild("Opened")
local tweenService = game:GetService("TweenService")
 
local debounce = true
clickDetector.MouseClick:Connect(function()
    if debounce == true then
        debounce = false
        if opened.Value == true then
            opened.Value = false
            
            tweenService:Create(frame,TweenInfo.new(0.65),{CFrame = Close.CFrame}):Play()
        else
            opened.Value = true
            
            tweenService:Create(frame,TweenInfo.new(0.65),{CFrame = Open.CFrame}):Play()
        end
        
        wait(0.65)
        debounce = true
    end
end)

This script uses a click detector that when clicked, fires a tweenservice which animates the door to animate open. We use the invisible parts to determine the position we want the visible door frame to move.

Sir_Highness explained it in a little more detail than I did:

If you want to learn about TweenServices and/or CFrame, I recommend two AlvinBlox tutorials:

Now, into the script

First, look at the 6th line of code:

local opened = model:WaitForChild("Opened")

This line of code is what originally created a local variable for the BoolValue that was named “Opened.” However, since there is no longer a BoolValue in the script, there’s nothing that can be referred to as “opened” so the script won’t work.

But why do we have to change it? Isn’t the attribute the child of the door model?

Incorrect, attributes are stored in the properties tab of an object. That’s why they are much more efficient. Because if you’re doing things like making a gun, you can put what’s worth 8 objects into just 1 using attributes, which will save space and keep things organized.

To replace this line so that it will get the attribute, simply delete “:WaitForChild” and replace it with “:GetAttribute” (assuming that you named the attribute the same name that the BoolValue was).

Next, you’ll want to get rid of every “.Value” in the script (which can be found on lines 13, 14, and 18 assuming you and I are using the same script).

Why?

Since attributes aren’t objects, they don’t have special property tabs individually. Therefore, when using “opened.Value” the script will attempt to index a boolean with a Value. In other words, it will attempt to find the properties for something that doesn’t have properties.

I’m not giving away what the fixed script should look like OR the model of the fixed version because:

  1. Attributes aren’t accessible to everyone at the time of posting this
  2. I’ve realized that if I just give you everything you aren’t learning.

This does not mean I will be taking down the original model, that will stay up.

Hopefully, this helps and will provide a better inside on the script! Have a great day!

5 Likes

Can you update this with proximityprompt?

5 Likes

Then can you give a code that we should use instead? :thinking:

That’s not how doors work irl. Doors can only open one way.

Thank you for your help! But when I was typing in the script , and tested the door , it didn’t work , however , I extracted the script from your model if that’s fine with you :smiley:

That is not true, double swing doors exist.

1 Like

how u meant to lock the mf door if it flips both ways. only way u would be able to lock it is if u had a really intense locking mechanism (talking about irl doors) but usually doors only open 1 way because it’s easier to lock it from one side. Double swinging doors either have to be heavy hinged or have locks at the top and the bottom and it’s just unconventional to have a double swinging door as its easy to break into.

Hi, I have a simple question. How could I possibly edit the door so it opens 2 ways instead of one (Depending on which side of the door your on it’ll open the opposite way) if that makes sense sorry im bad at explaining things!

like any other door?
a lock is in the middle of the door, you don’t need complex locks lol.

how to make door that bust when player has sprint on???

Very useful tutorial, but I kinda use a different door method:

  1. I create the base of the door, and duplicate it, resize it to be a pole, and name it hinge.
  2. I weld the base to the hinge, anchor the hinge, and unanchor the base.
  3. Finally, in the script, I rotate the hinge with TweenService when it’s triggered by either ClickDetector or ProximityPrompt.
3 Likes

Most likely it uses the touched event and checks if player has a special boolvalue like “isSprinting” set to true, or just checks the speed. But if you want to make it effectively, you will need an invisible hitbox part for it, so player won’t hit the door before he busted it.