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

Lerp never freaking works, code is erroring need breakdown?

hey i don't understand how lerp works and if someone can please give an explanation of the concept of lerp, i can't set my character primarypart cFrame because the lookvector is counted as a vector

super stupid and or i'm just retarded

	for i = 1, 20, 0.5 do
		hrp.CFrame:lerp(hrp.Position + hrp.CFrame.lookVector * 8, i/11)
		wait(0.08)
	end

1 comment

0

what is the error

1 answer

Simpliest explaination of lerp: it returns a value between the first and the last value based on the percentage you specify.

Let's say your first value is Vector3.new(0,0,0) and your destination value is Vector3.new(100,0,0)

local firstVal = Vector3.new(0,0,0)
local destVal = Vector3.new(100,0,0)

Now, lerping those values by let's say 0.3 would return Vector3.new(30,0,0)

print(firstVal:lerp(destVal, 0.3)) --> 30, 0, 0
print(firstVal:lerp(destVal, 0.7)) --> 70, 0, 0

Get it? The 0.3 means it will return like 3/10 of the distance.

Now back to your code, it errors because CFrame:lerp()'s first argument has to be a CFrame aswell, while you're passing a Vector3.

But you can fix it by using CFrame.new()

for i = 1, 20, 0.5 do
    hrp.CFrame:lerp(CFrame.new(hrp.Position + hrp.CFrame.lookVector * 8), i/11)
    wait(0.08)
end

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