Hi I am trying to make a part in the workspace rotate 90 degrees on the y axis and then stop but the part will progressively speed up and keep rotating past the point that I want it to stop. here’s my code.
local part = script.Parent
local rotate = part.Orientation.Y
wait(4)
for i = 1, 10, 0.0001 do
part.CFrame = part.CFrame:Lerp(part.CFrame * CFrame.Angles(0,math.rad(90),0),i)
wait(0.01)
end
Heres a video of the problem.
https://gyazo.com/21b533e5d4deb915ed111e091977ca38
any help would be appreciated
Your variable goes from 1 to 10, Lerp
makes the full translation between 0 and 1.
Write your for loop like
for i = 0, 1, 0.0001 do
and it will only rotate once.
I also recommend using TweenService for tasks like this, it saves you a lot of writing and has additional options.
In addition to @emojipasta’s post, you’re changing your target every iteration because you’re always trying to rotate towards 90 degrees offset from the current CFrame—but you just changed the current CFrame!
Same problem for the “start” CFrame.
Set the target at the top of the loop and re-use it.
local part = script.Parent
wait(4)
local start = part.CFrame
local target = part.CFrame * CFrame.Angles(0, math.rad(90), 0)
for i = 1, 1, 0.0001 do
part.CFrame = start:Lerp(target ,i)
wait(0.01)
end
But also yeah, use TweenService.
4 Likes