CFrame: Lerping with For Loop

Hello everyone! So I have been learning CFrame in Roblox LUA lately… I have come across the “Lerp” function that exists under the CFrame property. So my question is… I tried using a for loop to gradually move a part from one point to another using the lerp function and a for loop, but the parts won’t budge. Why is that?

My Code:

for i = 0, 1, 0.1 do 
	game.Workspace.IceShard.CFrame:Lerp(game.Workspace.IceShard2.CFrame, i)
end

You need to set the CFrame of the part with the method that you run.

for i = 0, 1, 0.1 do 
    game.Workspace.IceShard.CFrame = game.Workspace.IceShard.CFrame:Lerp(game.Workspace.IceShard2.CFrame, i)
end
1 Like

I think this topic belongs to Scripting Support

1 Like

Change:

for i = 0, 1, 0.1 do 

To:

for i = 0, 1, 0.01 do

Somewhat unrelated, but you may find TweenService to be useful for whatever it is you’re doing.

It’s easier to work with, since playing tweens does not yield your script, and thus your scripts don’t need to wait for your CFrame lerp to finish before continuing.

Double-check the syntax, a do is correct in that context:

image

3 Likes

Yeah, I know… However, I was just practicing learning the lerp function to get familiar with it.

1 Like

Go check out TheDevKing’s Channel he has a tutorial about lerping

1 Like