Let's say I have a function for Lerping a number.
-- function to lerp number
function numLerp(Start, Finish , Alpha)
return Start + (Finish- Start) * Alpha
end
Now I have this function which makes a part become transparent using that numLerp function above.
local Part = workspace.Part
local DesiredTransparency = 1
function numLerp(Start, Finish , Alpha)
return Start + (Finish- Start) * Alpha
end
for i = 0, 1, 0.05 do
wait()
Part.Transparency = numLerp(Part.Transparency, DesiredTransparency, i)
end
How can I do the same thing but based on time, not increments?
Edit
Okay. I managed to figure this much out.
If we take the number 1 and divide it by the increment which is 0.05 we get the number of increments in the loop which is 20. If we multiply the amount of time between increments (which in this case is roughly 0.3 seconds) by the number of loops which is 20 you get the amount of time it takes for the loop to complete which is roughly 6 seconds. Now I simply need to figure out how to apply this know so that my lerp function is based on time, not increments.

4 comments
A few questions. What is renderpriority and why is it set 1 above camera? When the animation is complete can I not unbind from renderstepped or disconnect or something? @ZarsBranchkin
Bind to renderstep registers a function that should get called every frame. Render priority determins when that function should get called. Might want to play around with that, but it seemed that running it after updating camera was a good idea. You can unbind, but I'd say it's better idea to leave it and update all animations with that function. The way I usually do that I have a table where I (.
(..) table where I put the "animations"(tables) that should play. These tables contain animation's duration, it's current playback time and a function that does the animation and accepts the alpha as argument. Once animation is over, it gets removed from animation table.
Alright thanks a lot. @ZarsBranchkin