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