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

How do I linearly interpolate integers without using a formula every time?

So I want to use the :Lerp() function on integers without having to use the formula b-a + ((b-a) * t) every. Single. Time. Notice how Vector3 and CFrame have a :Lerp() function? Here is what I mean:

StartVector:Lerp(EndVector,DeltaTime)
StartCFrame:Lerp(EndCFrame,DeltaTime)

Heck, even Color3 has it:

StartColor3:Lerp(EndColor3,DeltaTime)

But when I put this in the command line:

print((1):Lerp(2,0.5))

It returns this error: print((1):Lerp(2,0.5)):1: attempt to index number with 'Lerp'

Look, I know floats and numbers and stuff are different to Vector3, CFrame and Color3. But it would make life a LOT easier if there was a built in linear interpolation for numbers. If there are any answers let me know.

1 answer

You don't. It's either a value object with TweenService, a lerp algorithm, or the Lerp method for available data types. Numbers do not have methods in Lua, and Roblox isn't going to make such a drastic change.

The only reason why we can linearly interpolate specific data types is because they're a class that holds specific values. Numbers are not classes, therefore they cannot hold methods, constructors, or anything of the like.

..I just went in a circle. It's whatever. That should solve your issue. Cheers.

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