Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to use :lerp() to rotate & change position of part simultaneously?

Asked by
Spooce 78
9 years ago

I'm trying to make a little animation with a lever. It will slowly be pulled down when clicked. I can't seem to get it to rotate and change its position at the same time though. I've tried threading.

Suggestions?

local Lever = script.Parent
local Enabled = false

StartCFrame = Lever.CFrame
EndCFrame = CFrame.new(118.1, 107.671, 70.582)

function Position()
    for i = 0, 1, 0.1 do
        Lever.CFrame = StartCFrame:lerp(EndCFrame, i)
        Enabled = false
        wait(0.05)
    end
end

function Rotate()
    for i = 1, 150 do
        Lever.CFrame = StartCFrame * CFrame.Angles(math.rad(i), math.rad(0), math.rad(0))
        wait()
    end
end


Lever.ClickDetector.MouseClick:connect(function()
    if not Enabled then
        Enabled = true
        Spawn(Position)
        Spawn(Rotate)
        Enabled = false
    end
end)

1 answer

Log in to vote
0
Answered by 9 years ago

Try making a different script that also detects when it happens.

Like putting in a different script.

local Lever = script.Parent
local Enabled = false
function Rotate()
    for i = 1, 150 do
        Lever.CFrame = StartCFrame * CFrame.Angles(math.rad(i), math.rad(0), math.rad(0))
        wait()
    end
end

Lever.ClickDetector.MouseClick:connect(function()
    if not Enabled then
        Enabled = true
        Spawn(Rotate)
        Enabled = false
    end
end)

Place that into a different script?

crosses fingers hope it works!

Happy Thanksgiving!

Ad

Answer this question