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!