How would I restore the position of this lever?

oh then add a wait(.01) i forgor lol

Nope

I gave up on this stuff and just started sending the original cframe to a cframe value stored before my object moves. Then to restore, I aimed the movement back on the stored cframe.Value. Turns out this works at any angle. so … There is a cframe that works just like a bool. You can store a cframe and get that data back that way. Even if the object moved to a new position and then you wanted to move it back.

Something like this in pseudo code …

local db = false
function()
 db = not db

 if db then 
   store cframe value to a cframe.Value
   move lever down
 else 
   get stored cframe.value
   move lever back to that value
 end
end

Try:

function Electronics.Lever(Lever, LogisticPort)
    local DragDetector = Lever.DragDetectorPart.DragDetector
    local main = Lever.Main
    local Motor6D = main.Motor6D

    local offset = CFrame.new(-0.01, -0.677, -0.3)
    local initialDragY = 0  -- Initialize the initial drag position to 0

    DragDetector:GetPropertyChangedSignal('DragFrame'):Connect(function()
        local currentDragY = DragDetector.DragFrame.Position.Y
        local deltaDragY = currentDragY - initialDragY  -- Calculate the change in drag position
        local clampedDragY = math.clamp(deltaDragY, -main.Size.Y + 0.7, 0)
        local powered = math.floor(clampedDragY / (-main.Size.Y + 0.7) * 100) / 100
        Motor6D.C1 = offset * CFrame.new(0, -clampedDragY, 0)

        setPowered(Lever, powered)

        -- Update the initial drag position for the next frame
        initialDragY = currentDragY
    end)
end


Nope, sorry.

Why you are changing position of the lever instead chaning the current position?

Sorry I don’t understand, I am changing the motor6d c1 of the lever instead of the position and cframe because I need this lever to be welded onto moving vehicles later on, and the only way that I know of for moving/tweened parts to work on unanchored, moving parts is by welding via motor6d.

Try again, please. I updated it.

Well, what i am seeing in your code that you are setting new cframe of c1 every time is dragged

Motor6D.C1 = offset * CFrame.new(0,-DragY,0) what are you doing here is just setting offset and the Y axis and never get the current Y axis of the c1

you just need something to get the current cframe and add the current cframe to the new cframe and you need to check if it’s not going out of the lever zone/offset.

example like how drag ui works.

1 Like


Nope, but thanks for all the replies!

I already get the cframe and convert it into a vector3 here, and I did try yoshicoolTV’s script and Swetch29’s with me adding the inital position, I also did something similar before but it didn’t work.

local DragY = math.clamp(DragDetector.DragFrame.Position.Y,-main.Size.Y + 0.7,0)

Can you upload your lever model then, please?

If you do it’ll be easier to solve your problem by making it easier to debug the solutions we give you.

Sure!
levermodel.rbxm (12.3 KB)
Does this work?

A lot easier when you give what’s needed to fix the problem

local Lever = script.Parent
local DragDetector = Lever.DragDetectorPart.DragDetector
local main = Lever.Main
local Motor6D = main.Motor6D
local offset = CFrame.new(-0.01,-0.677,-0.3)

DragDetector:GetPropertyChangedSignal('DragFrame'):Connect(function()
	local DragY = math.clamp(DragDetector.DragFrame.Position.Y, -main.Size.Y + 0.7, 0)
	local powered = math.floor(DragY / (-main.Size.Y + 0.7) * 100) / 100
	Motor6D.C1 = offset * CFrame.new(0,-DragY,0)
end)


Nope

edit: I guess I should’ve included the model in the original post in the first place, my bad.

Works perfectly for me … you have something else wrong.
Try that in a new game. And how did you post that video?

I used gyazo video
https://gyazo.com/9b7b5c8ee1b665581a0594f7da867482
and downloaded it, then sent it

Tried it in another game, copy pasted the exact model and added the script you provided, works the same.

Maybe I don’t understand what you looking to do here.


I just want the lever to retain its position after the player has already used it, like here in this video, I can move the lever down with studio tools, then move it up again from the same position or down, that is what i’m aiming for.

I messed with it a lot … I’m lost. This is a beta thing so … who knows if it’s totally working.
At this point I’ll let others look at it … maybe look here drag-detectors

It can do a pull down well … so make a pull up version and swap them quick. lol

There is a drawer in that link in a video doing just what you want. SAD they don’t show the code for that. “Here is what we can do with it and well good luck” …

Ok did a bit of digging and found this … A ton of information and example programs.
Your answer has to in there someplace.