Im working on a button thats supposed to open a door, but the hull above the button doesnt want to open.
And here is a screenshot from the script with i tried to make it work
And here is a screenshot from the error i get when i click on the hull
Im working on a button thats supposed to open a door, but the hull above the button doesnt want to open.
And here is a screenshot from the script with i tried to make it work
And here is a screenshot from the error i get when i click on the hull
The X,Y and Z of a Position/Orientation are readonly.
You’ll need to set the Position/Orientation to a Vector3.
If you want to change one value of a Position/Orientation you can do something similar to:
Something.Position = Vector3.new(Something.Position.X, 5, Something.Position.Z)
In this example, we’re only setting their Y Position to 5, the X and Z and not changed.
Greetings!
Currently, the XYZ subproperties of position are read only. This means you cannot edit their value. If you want to change the position of an instance, use Vector3’s or CFrame’s instead. Here’s a very brief introduction:
b.Position = Vector3.new(X, Y, Z)
Vector3 is a datatype that allows you to store 3 vectors. In Roblox, Vector3’s are mostly used for positioning and therefore the 3 values are very often associated with X, Y and Z (see code above). This is the most simple way to move a part, this means there are some setbacks. These include:
Okay, how do we fix this then? That’s where the CFrame datatype comes in! CFrame’s are a tad more difficult to use than Vector3’s as they are actually 12 dimensional! CFrame’s and Vector3’s can be combined into a new CFrame, allowing us to do something around the lines of this:
b.CFrame = b.CFrame + Vector3.new(0, 1, 0)
The code above will move the part called b
up one stud.
Possible solution
Considering you also want to change the rotation of your part, here’s what I’d do:
First off, duplicate (CTRL + D) the part b and move it to your desired position. Make this new part invisible as well as uncollidable and anchored.
Now, let’s do some scripting! We currently have one part positioned at the closed state and another one at the opened state. We can get the CFrame’s of these parts and position the visible one accordingly.
local b_OriginalCFrame = b.CFrame -- Lets us remember b's original position.
b.CFrame = c.CFrame -- Asuming C is the invisible part, this will open the lid.
b.CFrame = b_OriginalCFrame -- This will reset the lid to its closed state.
CFrame’s are tricky, it’s okay if you don’t understand! There are lots of guides around the internet, so finding some learning resources shouldn’t be too hard. Good luck!
Side note
You don’t need value instances to save values such as true or false. Instead of doing:
local open = script.Parent.Parent.open.Value
You could do:
local open = false
thx @return_end1 and @0skarian but i found this solution for me
i just made one in the closed state (b) and one in the open state (b2)