Making a "Linear Object"

No idea what to call it, but simply put, just like a spring but instead of the springy motion, it’s just a linear motion with 3 options: position, target, and speed

This is what I have right now, but theres stuttering once it reaches its target it seems like, and stuff gets glitchy at high speeds. My goal is to allow it to work with vectors at the same time too, so the position and target could be either numbers or vector3s.

local line = {}
local tick = tick
local clamp = math.clamp
local sign = math.sign
local inf = math.huge

– a + ((b - a) * c)
function line.new(init)

local t0 = tick()
local speed = 1
local target = init and init * 0 or 0
local position = init or 0

local function update(time)
	local dt = time - t0
	local dist = target - position
	position = position + speed * dt * sign(target - position)
	t0 = time
end

return setmetatable({},{
	__index = function(_, index)
		local time = tick()
		if index == 'p' then
			update(time)
			return position
		elseif index == 't' then
			return target
		elseif index == 's' then
			return speed
		end
	end,
	__newindex = function(_, index, value)
		local time = tick()
		if index == 'p' then
			position = value
			update(time)
		elseif index == 't' then
			target = value
			update(time)
		elseif index == 's' then
			speed = value
			update(time)
		end
	end
})

end

return line

any help is appreciated

How often are you updating it, are you using a while true do loop?

it shouldnt matter how often it’s updating, it updates every time its used and is based on delta time, so it’s supposed to compensate for the time between updates.
im going to be updating on renderstepped tho
only issue im having rn is the math cuz i suck at it ig