Very helpful for beginners! Thanks for sharing!
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.
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.
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.
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.
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).
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!
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:
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:
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:
- Attributes aren’t accessible to everyone at the time of posting this
- 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!
Can you update this with proximityprompt?
Then can you give a code that we should use instead?
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
That is not true, double swing doors exist.
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:
- I create the base of the door, and duplicate it, resize it to be a pole, and name it hinge.
- I weld the base to the hinge, anchor the hinge, and unanchor the base.
- Finally, in the script, I rotate the hinge with TweenService when it’s triggered by either ClickDetector or ProximityPrompt.
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.