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

How do you use CFrame with in pairs loop?

Asked by 9 years ago

So I want to make a part move until a certain point, how do I do that? I don't know how/what functions/code I should use because I have only been scripting for 2 weeks, but I am pretty experienced.

0
Why would you use a `pairs` loop to do this? BlueTaslem 18071 — 9y
0
Also, don't say you are "pretty experienced" if you have been writing code for 2 weeks. I've been writing code for around 9 years and I still run into problems. Saying that, especially when it's not true, isn't helpful. BlueTaslem 18071 — 9y
0
^, Hes attempting to make a Tablet Admin or some sort of Walking pet.. MessorAdmin 598 — 9y

1 answer

Log in to vote
0
Answered by
SurVur 86
9 years ago

You don't need a generic for loop, just a regular one.

pointA = workspace.Part1.Position
pointB = workspace.Part2.Position

for i = 0, 1, .01 do --Change the .01 to your own increment if you wish
    local newPoint = pointA:Lerp(pointB, i)
    workspace.Part1.CFrame = CFrame.new(newPoint)
    wait(.05) --Change the wait to your own, too
end

workspace.Part1.CFrame = workspace.Part2.CFrame --Just making sure it ends up in the right spot

This should work between any two points. It relies on the :Lerp() function. It basically finds a point in between two other points given the two points and an alpha. For more check this out.

Ad

Answer this question