RunService and Lerp problem

But how do you do it if you wanna fire it for all clients when they all get loaded?

If a new client joined, it resets?

You tween it on the client and update the server to the goal when it’s finished, so when a new client joins they see the final result.

1 Like

Quick question, why does the alpha prints 0.9999999999 and not like 1… something?

It printed out a value of 10 for the steps variable. I mean like 10 is less than 10?

At the end of the loop, steps variable is 10 and alpha is 0.9999999999999.

I don’t really know, but that’s probably how floating point decimals work.
and steps is an integer that’s why it gets a whole number

1 Like

Do you know an answer to this?

1 Like

And for this how should I do it?

Estimate the time it takes for the tween to be completed and update the part CFrame on the server.
If your tween is 1 second long then task.wait(1) then set the part’s CFrame.

1 Like

The whole point of lerp is to be used in a loop. Lerp will not work as intended if not in a loop. This is because you’re taking the fraction (alpha) of that distance over a period of time. Lerps are normally used in RS Loops too.
There is a lot of misinformation in this thread.

  1. RS Loops are a bit laggy, but you’ll often have to overcome it. Minimise the load on these loops and you’ll be fine.
  2. Lerps are not laggy either. In fact, tweens are even laggier because they require more calculations for each point (because of EasingStyles and EasingDirections), whereas Lerp’s calculation is literally tiny. if you’re curious:
local function lerp(a, b, t)
	return a * (1 - t) + b * t
end
  1. Lerps are designed to be used in loops. They update once per iteration of loop, whereas Tweens are standalone and are meant to be called once. This is why it’s very common to see lerping in RunService loops and vel sim.
    Basically, you either use lerp in a loop or just 1 tween.

Hope that cleared things up!

1 Like

If you set alpha to 1, it’ll go instantly, as it will complete the whole distance in 1 call.

I disagree, more often than not the reason they’re laggy is because it’s causing the server to replicate something to the client constantly (aka lerping or tweening on the server)

That’s not really true. Lerping (Linear Interpolation) is just tweening but you can control more variables like

  • Resolution (how smooth it is)
  • EasingStyle (by using curve equations)
  • Ability to resume at a certain time
local function linear(x) 
    return x
end

local function easeInQuad(x)
    return x * x
end

local function Lerp(a, b, x)
    return a + (b - a) * x
end

local function Tween(instance, resolution, time, curveFunc, goalProperties)
    -- Default:
    curveFunc = curveFunc or linear

    for property, value in pairs(goalProperties) do
        -- Create a new thread
        -- You can also save the thread if you want to add a cancel function
        task.defer(function()
            local step = 1/resolution
            local timeInterval = time/resolution
            local origin = instance[property]
            -- This is not a very good system as task.wait() doesn't wait precisely, it is better to use RunService.Heartbeat and a clock system instead.
            for i = 0, 1, step do
                local alpha = curveFunc(i)
                task.wait(timeInterval)
                instance[property] = Lerp(origin, value, alpha)
            end
        end
    end
end

-- Example usage
Tween(part, 100, 5, easeInQuad, {CFrame = CFrame.new()})
Tween(part, 50, 10, nil, {Transparency = 1, Size = Vector3.one * 10})
1 Like

Yes, I am aware the lerps work as intended when in a loop, but connecting it to RunService is not an ideal solution as it runs forever unless you disconnect it.

But also…

I have never seen this formula used to describe a lerp, would you mind explaining it :thinking: ? I use:

a + (b - a) * t
1 Like

Compared to a Lerp, a Tween instance is far laggier because there are many factors to consider, and each graph will be plotted differently based on settings, whereas for Lerp it is constant and unchanging.
However, there is realistically no difference. Tweens are designed to be used outside of loops and lerps are designed to be used inside loops.

Are we talking about RenderStepped or Heartbeat? Because the former is obviously not going to be nearly as laggy on the client as the latter.

I use lerps mostly for constant things that happen all the time, like camera manipulation. You only need to use lerps for things like this, because most other times they aren’t constant and you can get away with using tweens instead.
With regards to the formula - it’s basically the same thing. Your version is more common and perfectly acceptable.
We can plug in values: Let’s take a = 1, b = 2, t = 0.5. This basically means halfway between 1 and 2 (1.5). Plugging it in, we get:
1 * (1-0.5) + 2 * 0.5
which simplifies to
1 * 0.5 + 2 * 0.5
which is 0.5 + 1 = 1.5, which is what we expect :+1:
This calculation is the one I remember but the other one is the easier one to use.

1 Like

Do you know what’s wrong with my post above? I’m experiencing weird stuff with RunService.

1 Like

I don’t know what your concept of laggy is but RunService loops were not and are not laggy just because you’re using them. It’s simply ran every frame, a while true loop with a task.wait() for each iteration is the same thing.

To add more to this, RenderStepped and Heartbeat on the client is both based on player’s fps so they don’t “lag” more than the other

How laggy your loops are is solely because of your code, there’s nothing to do with using the loops themselves

What do you mean by constant?? Camera Manipulation can be used with Tween just as fine? The new tween just cancel the previous one if you’re saying that it changes destination every now and then.

TweenService is just an API to help users deal with smooth movements easier. TweenService is in fact just Lerping every frame (RunService). This is the delta value I got from a .Heartbeat of a Tween from a value of 0 to 1 (the delta is different because it is increased based on deltaTime)


Before you say that I can only print every frame but it is calculated multiple times in each frame for maximum “smoothness”. No, they don’t do that, you only need to update the values on every new frame on the client, what’s the point in computing 300fps while your monitor can only render 30fps?

Lerping is also just Linear Interpolation, it’s not designed to be in loop, a lerp doesn’t always have to do with smooth movements. It can be used to make bezier curves and much more, it’s just a math formula that computes a value in between 2 points given a percentage/alpha.

Please research before you try to prove a point.

Try sending a remote to the client and let it handle the Lerp, if I’m correct the activity on both sides should be normal

Wait, why not run it inside a local script? like no need to fire a remote.

If you don’t do that, the other clients won’t see it, the tween will only be on that client.