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

How to rotate and move a part at the same time with a lerp?

So I got a script that should make it where the part rotates and moves up and down with a lerp, but it seems to only rotate... I know I'm doing something wrong but what is it? I'm not very good at scripting.

Here's the script:

local part = script.Parent

local start = part.CFrame * CFrame.new(0, 0, 0)
local finish = part.CFrame * CFrame.new(0, 0.5, 0)
local rotstart = part.CFrame * CFrame.Angles(0, 0, -0.03)
local rotfinish = part.CFrame * CFrame.Angles(0, 0, 0.03)

while true do
for time = 0, 2, 0.2 do
    local progress = 1 - math.cos(time * math.pi)
    part.CFrame = rotstart:lerp(rotfinish, progress)
    wait()

end
end


while true do
for time = 0, 2, 0.2 do
    local progress = 1 - math.cos(time * math.pi)
    part.CFrame = start:lerp(finish, progress)
    wait()

end
end

1 answer

✓ Accepted answer

The problem is that you have 2 different loops. The first while true do loop will never finish, meaning that the second will never start.

You should only have 1 loop and 1 command to lerp. In this case, I believe we can just merge the CFrames like this:

local part = script.Parent

local rotstart = part.CFrame * CFrame.Angles(0, 0, -0.03)
local rotfinish = part.CFrame * CFrame.Angles(0, 0, 0.03) * CFrame.new(0, 0.5, 0)

while true do
	for time = 0, 2, 0.2 do
		local progress = 1 - math.cos(time * math.pi)
		part.CFrame = rotstart:lerp(rotfinish, progress)
		wait()
	end
end

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