Possibly not the best solution, but here you go:
We’re going to be using CFrames, so try to make sure you have at least a little bit of understanding on how it works (if not, just think of it like Position and Orientation had a baby)
Get the script
Now, we’re going to be using this CFrameValue.txt (394 Bytes) script I made to get something I’ma call a “RelativeCFrame”. Too complicated for me to explain, so just think of it as magic for now.
Step 1: Getting the “Closed” and “Open” CFrame
Don’t want to get into too much detail here, so just do as I say:
- Make sure your lever is in the “Closed” position
- Select your “lever” part in the Explorer
- Select the part your lever rotates/orientates itself around, the “Base”
- Run the script above in the command bar
After this, you should have selected a CFrameValue. Name it “ClosedCFrame”
Do this again BUT for step 1 make sure the level is in the “Open” position instead, and name the CFrameValue to “OpenCFrame”
Step 2: SCRIPTING!
Now mostly due to the fact that it is currently almost 1 AM and for you to understand this easily I will be explaining this in a nutshell:
We’re going to be using the CFrames we stored in our Values and mapping them onto the part it orientates around the “Base”.
First, we get our CFrameValues, parts, and BaseCFrame
local ClosedCFrame -- change this to where you put it
local OpenCFrame -- change this to where you put it
local Lever -- the lever part
local Base -- the base part
local BaseCFrame = Base.CFrame
Finally, when we want to set the Lever in an Open or Closed position, we can do so like this:
-- Open
Lever.CFrame = BaseCFrame * OpenCFrame.Value
-- Closed
Lever.CFrame = BaseCFrame * ClosedCFrame.Value
You can also use Lerp to Tween it smoothly, however I’ll leave that up you to do, lemme know if you need help, good luck!