Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.