I just looked at your code again, and realized why it wasn’t looping. The code is actually looping just fine, in fact if you stuck a print() in the loop you will see that after it plays the first time, it does actually repeat. However, I want you to look at something.
part1.CFrame = part1.CFrame:Lerp(endPart.CFrame, i) – part one to end
Look at this line. What you are doing is taking the current CFrame of part1, lerping that to your endPart CFrame, and setting that value as part1’s new CFrame. This means that when your animation finishes, part1’s CFrame is equal to endPart.CFrame. Then, when you restart this loop, you have nothing in your code that resets part1’s CFrame back to whatever the start is.
So to fix this, you need to create a second part that indicates where the start of the animation should be, which would mean that when the loop plays a second time, instead of taking the lerp of part1’s cframe (which is already at the endpart cframe), you are taking the lerp of the start CFrame and end CFrame.
Here’s a cleaned up version of your script: (note that you need to create two additional parts inside your model, one called Start and another called OtherStart)
local laser1 = workspace.Bank.Lasers.Laser1
–[[You do not need to use GetService() to grab workspace, instead you can simply type workspace and it will be there for you. This only works for workspace though, not other services.
Also, creating a variable for your laser is probably a good idea for keeping your code easier to read and edit.]]
local part1 = laser1.Part1
local part2 = laser1.Part2
local startPart = laser1.Start
local otherStartPart = laser1.OtherStart
local endPart = laser1.End
local otherEndPart = laser1.OtherEnd
while true do
for i = 0, 1, 0.02 do --Remember that the ending value of i should be 1, not 2.
part1.CFrame = startPart.CFrame:Lerp(endPart.CFrame, i) – part one to end
part2.CFrame = otherStartPart.CFrame:Lerp(otherEndPart.CFrame, i) – part two to end
wait() --You really only need one wait() here, no need to double up or anything.
end
end
[code ended]
Now the other script someone replied here is perfectly good; in fact, TweenService is probably the better thing to use here, since it lets you tween other values like color and transparency. But I just felt like I owe you a corrected version of your original script, since I somehow missed the issue initially. This should be helpful for learning what went wrong!