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

CFrame:lerp() not functioning correctly?

I've made a loop to try get the lerp() function to work, but it doesn't do anything.

wait(2)
print("Moving") --Prints
for i = 0,1,0.1 do
	script.Parent.Plat.Middle.CFrame:lerp(script.Parent.Floors.Floor2.CFrame,i)
	wait()
end
print("Stopped") --Prints almost immediately 
wait(5)
print("Moving")
for i = 1,0,-0.1 do
	script.Parent.Plat.Middle.CFrame:lerp(script.Parent.Floors.Floor1.CFrame,i)
	wait()
end
print("Stopped")

For reference, I replaced the print with warn to get timing

22:47:34.631 - Moving
22:47:35.003 - Stopped

GIF of what's happening

7 comments

0

Try increasing the wait, since it is very small, and may appear to complete instantly to human eyes (also, running a test in studio usually makes you miss out on a second or two of scripts).

0

^ Sadly, not the case.

0

This should work then. There is nothing that could possibly break this. The loops is obviously running - maybe there is something preventing the part from moving?

0

It's CanCollide False, unless it's just once again one of ROBLOX's glitches...

0

I use lerp all the time for CFrame animations. I'm not having any trouble with it. The code looks like it should work fine.

2

You have to define the cframe as the lerp. Say script.Parent.Plat.Middle.CFrame = script.Parent.Plat.Middle.CFrame:lerp(script.Parent.Floors.Floor2.CFrame,i) and you should be good to go

0

^ Danke

1 answer

✓ Accepted answer

:lerp() computes a value. It doesn't do anything.

You would not expect a + 1 to modify a. Similarly, using :lerp() on script.Parent.Plat.Middle.CFrame doesn't modify that CFrame.

You also shouldn't flip the direction of iteration in the second loop; you already flipped Floor1 and Floor2. In that case, you have code repetition, and you can greatly shorten your code:

model = script.Parent
platform = model.Plat.Middle

function move(from, to)
	-- because of problems with inaccuracy, it's wiser to go by integers and divide inside
	for i = 0, 10 do
		platform.CFrame = from:lerp(to, i/10)
		wait()
	end
end


wait(2)
move(model.Floors.Floor1.CFrame, model.Floors.Floor2.CFrame)
wait(5)
move(model.Floors.Floor2.CFrame, model.Floors.Floor1.CFrame)

Also note that your "from" in the :lerp should not be the thing you're modifying -- it should be the start position.

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