Is it possible to make a wait script until the lerp is completed like a tween?

Hi! So I’ve been trying out lerping for a while now and haven’t found a good explanation on how I would make a wait script until the lerp is completed, just like how there is a tween function where you can wait till it’s done. I’m making a lerp go to multiple parts but it wants to go to every part instead of just one. I’m only really asking this since I’m going to be using this for multiple different things and wondering if there is anything to help this. Thanks!

Could you post some code please? And what have you tried so far?

While it’s not possible to directly wait for a lerp, there are a couple workarounds you could do.

local RunService = game:GetService("RunService")

local function lerp(start, finish, t)
	return start + (finish - start) * t
end

local function waitForLerp(object, property, targetValue, duration)
	local startTime = tick()
	local startValue = object[property]

	while tick() - startTime < duration do
		local elapsedTime = tick() - startTime
		local t = elapsedTime / duration

		object[property] = lerp(startValue, targetValue, t)

		RunService.RenderStepped:Wait()
	end

	object[property] = targetValue
end

local part = game.Workspace:WaitForChild("LerpPart")
local targetPosition = Vector3.new(-39.135, 0.5, 8.033)
local duration = 2

waitForLerp(part, "Position", targetPosition, duration)
print("Lerp finished")
1 Like