How To Make An Animated Door (Click To Open)

NOTE (7/30/23): This tutorial covers the basics of making an animated door. However, it is very outdated for my skill level (since this tutorial is almost 3 years old) and not the most efficient way to accomplish this. If you want a more advanced method of creating an animated door, I’d reference some of the replies left under this post.


Introduction

So I was looking for a tutorial on how to make an animated door in Roblox. However, I could not find anything on google OR the developer forums of what I wanted. So then, I decided I would try to figure it out myself and play around with things. Eventually, I figured out what I wanted and I was very happy. I have decided to share my creation with you guys so that YOU can create this type of door:


Getting Your Parts

So the first step is to create the door. You can be as detailed or as plain as you want, I’m just going to use a singular block to get the point across. You can name this part whatever, it won’t affect the script. Make sure that the part is Anchored and CanColide is on. Congratulations you have a block (you’re so talented)

Next, you’ll want to duplicate this block. Keep it in the same position. This will be the local used in the script to define what position the block will be in when the door is closed. Name this part “DoorClose.” Change the transparency (on the duplicated block) to 1 and turn CanCollide off. Congratulations you have two blocks that are almost identical! Do I really need to show a picture?

Finally, you’ll want to duplicate the duplicated block. Keep all the properties the same, but move it into the position you want the block to be facing when the door is open. Name this block “DoorOpen.” Of course, you can add more blocks around it like I did to let it look more like a door. Those blocks can be called whatever you want.

Now, you’ll want to hover your mouse over Workspace, click the plus, and add a Model. Name that Model whatever you want, I’m just gonna name it Door. Now, drag all the parts into that Model. You’re going to add a few more parts into this model and then you’re done with a building, and you’ll move on to scripting.

Next, you’ll hover your mouse over the model, click the plus, and add a BoolValue. This is important for the script itself. Rename this value to “Opened” and make sure that “Value” under the properties is off. Next, hover your mouse over “DoorPart” and add a ClickDetector to the DoorPart. All the properties in the ClickDetector can remain the same. Now you’ll add one more thing to the DoorPart, which is a script. Name the script whatever you want. Congratulations (for the third time), you’re done with the building process and now can move on to the script! It should look like this in your explorer tab (without the extra parts that I mentioned earlier):
Screen Shot 2020-11-12 at 1.59.21 PM


Scripting

While working on this little tutorial, I started to notice that my script was VERY bad, because it didn’t work 100% of the time, and it wasn’t that smooth. While looking through models, I found a door script with the same concept that worked way than mine, made by a small developer named “abe_o0.” I didn’t want to plagiarize his work so credits to him for giving the better foundations of the script, I had to tweak it so it could work with my door more.

Double click on the script, and copy and paste these lines of code into it:

Script
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)

You can also customize this script just a tiny bit. As of right now, the door opens and closes in sixty-five hundredths of a second. That’s the speed it was at in the video at the top. If you want it faster or slower, just simply find all the spots where it says “0.65” and change that to however many seconds or milliseconds you want. I would really suggest keeping the wait time the same as the Tweeninfos because when I tried making it longer than them it broke the door. But if you want to experiment go right ahead!

And congratulations (This is the last time I’ll say congratulations I promise)! You have made a door with a smooth animation to open and close a door! Have fun with it, and have a great day!

EDIT: If you are confused (or just too lazy), you can use this model to add the finished version into your game: Animated Door (Click To Open) - Roblox


Please look at the solution below if you want to know how to use this door model with the new attributes feature


77 Likes

Do there need to be any transparent parts?

Did you mean change the transparency to 1

wow thank you so much! lol i just made an airport model a few minutes ago and i was wanting to know while doing it how to make a door move. thank you!

1 Like

You’ll want to make the parts that are supposed to be named “DoorClose” and “DoorOpen” transparent.

Yeah, but you said turn the transparency to 0.

When you turn the transparency to 0, it turns visible.
when you turn it to 1, it turns invisible.

1 Like

Oops! Thank you for pointing that out, that was error in my typing.

1 Like

no, problem

everyone does mistakes once in a while :slight_smile:

1 Like

I feel as though this would be better suited for Community Resources - this is not a tutorial on making a door so much as it is a tutorial on how to copy and paste code.

4 Likes

thanks for teaching me, now I know how to make a door!

1 Like

Maybe you could make it a bit more advanced and have the door go to a certain side depending on what side of the door you click on.

Do you mean as in a double door?

No, I mean as if you click on one side it opens to the other, and if you click on the other side, it opens the other side.

Very helpful for beginners! Thanks for sharing!:+1:

2 Likes

Bad tutorial, bad code, something in Toolbox I could find, also using wait() as debounce, doesn’t seems good tbh.

You probably shouldn’t serverside the tween. You should have it local and replicate the local tween across all clients. Serverside tweens can be laggy and just be… bad.

3 Likes

When I said that I didn’t expect you to take it at face value. It should go without saying that when phrased as a “faux-tutorial” this should be in community tutorials, however it serves more benefit reimagined as a community resource.

1 Like

Well, that wasn’t exactly a tutorial. I’m a beginner and would like to understand how the script works, not copy and paste. But thanks for sharing your knowledge.

1 Like

I thought it was a fine beginner level tutorial which shows a simple way of animating a door. Do you have any specific questions about the script used? It uses a click detector event to fire the function which uses tweenservice to animate the door(update the visible door’s CFrame) from the CFrame of the invisible closed door part, to the CFrame of the invisible opened door part. CFrame is the position and orientation of the parts.

2 Likes

This seems like a really nice tutorial for beginners but, if anyone wanted to make a actual game, I wouldn’t recommend this, instead, I’d recommend using module scripts and, not using multiple ClickDetectors since they may use more resources than needed, instead, you can change the parent of your ClickDetector and, a while true do loop to do a magnitude check; if a door is within x amount of studs (e.g. 7), change the parent of your ClickDetector and, if it’s clicked, fire a remote event to the server where an animation will be played based on the state of the door (open/closed), also, remember to do sanity checks on the server too.

Note: I’d recommend adding sanity checks since exploiters can fire ClickDetectors without being close to one (this is assuming you handle ClickDetector.MouseClick events on the server).

3 Likes

Thank you! I don’t know how to use the tweenservice, but I’ll see it. I’m watching TheDevKing tutorial by the the way.

When I see the tutorial I’ll come back here, thanks for helping me!

1 Like