How use Lerps and why is better than Tween?

I know that there is already a forum like this, however I am Brazilian and I cannot understand well without examples, I need to learn how to use it, I am trying to replicate my skill

https://gyazo.com/329dcac5c09198b32b93b8f1a263f935

However using lerps was like this

https://gyazo.com/0024cfd3dda5fd6ffbb192e1bdc5082f

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PureBlaster = ReplicatedStorage.Skills.Pure.PureBlaster.Remotes.PureBlaster
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Casting = require(game:GetService("ServerStorage").CheckCastingSkill)
local CheckSkill = require(game:GetService("ServerStorage").CheckCanSkill)
local KDa = require(game:GetService("ServerStorage").Kda)
local Stun = require(game:GetService("ServerStorage").BadEffects.Stun)
local Shield = require(game:GetService("ServerStorage").Shields)
local StunEvent = game:GetService("ServerStorage").Events.Stun
local P
local Stuned = false
 
StunEvent.Event:Connect(function(player)
   
end)
 
 
local function pureBlasterF(player)
   
   
    Casting.Set(P.Character,0)
    local Meshes = script.Meshes
    local Character = player.Character
    local Humanoid = Character:WaitForChild("Humanoid")
    local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
    local MindDamage = player.Stats.Mind.Value.Value
    local MindSecondD = player.Stats.Mind.Value.Value * 0.10
    local Model = Meshes:WaitForChild("Model"):Clone()
    local BlasterP = Meshes:WaitForChild("BlasterP"):Clone()
   
    Model.Parent = workspace
    Model.Name = player.Name.." Blaster"
   
    local n = math.floor(100 * 10)
    wait(0.2)
   
    local Track =  Humanoid:LoadAnimation(script.Animation)
    Track:Play()
   
    if Stuned == true then
       Model:Destroy()
       BlasterP:Destroy()
       return
    end
 
    local PureB = Meshes:WaitForChild("PureB"):Clone()
    PureB.CFrame = Character:WaitForChild("LeftHand").CFrame
    PureB.Size = Vector3.new(2,2,2)
    PureB.Parent = Model
   
    local PureB2 = Meshes:WaitForChild("PureB"):Clone()
    PureB2.CFrame = Character:WaitForChild("RightHand").CFrame
    PureB2.Size = Vector3.new(2,2,2)
    PureB2.Parent = Model
   
    local weld = Instance.new("WeldConstraint")
    weld.Parent = Model
    weld.Part0 = PureB
    weld.Part1 = Character:WaitForChild("LeftHand")
   
    local weld2 = Instance.new("WeldConstraint")
    weld2.Parent = Model
    weld2.Part0 = PureB2
    weld2.Part1 = Character:WaitForChild("RightHand")
   
    if Stuned then
       Model:Destroy()
       PureB:Destroy()
       PureB2:Destroy()
       BlasterP:Destroy()
       return
    end
   
    wait(0.75)
   
    Shield.Increase(Character,1,1)
   
    coroutine.wrap(function()
    for count = 1,5,1 do
        if Stuned then
            Model:Destroy()
            PureB:Destroy()
            PureB2:Destroy()
            BlasterP:Destroy()
        end
        PureB.Size = PureB.Size + Vector3.new(1.8,1.8,1.8)
        PureB2.Size = PureB2.Size + Vector3.new(1.8,1.8,1.8)
        wait() 
    end
        PureB:Destroy()
        PureB2:Destroy()
        if Stuned == false then
          HumanoidRP.Anchored = false
        end
    end)()
   
    BlasterP.Parent = Model
    BlasterP.CFrame = Character:WaitForChild("Head").CFrame * CFrame.new(0,3,-2)
    BlasterP.ParticleEmitter.Rate = n
    BlasterP.Orientation = BlasterP.Orientation + Vector3.new(0,-90,0)
    BlasterP.Size = Vector3.new(1,15,15)
    BlasterP.Anchored = true
 
    BlasterP.Size = BlasterP.Size:Lerp(Vector3.new(100,15,15),1)
    BlasterP.CFrame = BlasterP.CFrame:Lerp(CFrame.new(BlasterP.CFrame.X,50,BlasterP.CFrame.Z),1) --Here the problem
       
    local transp = 0.1
         BlasterP.ParticleEmitter.EmissionDirection = Enum.NormalId.Front
         BlasterP.ParticleEmitter.Speed = NumberRange.new(3, 3)
    for count = 1,20,1 do
         BlasterP.ParticleEmitter.LightEmission = BlasterP.ParticleEmitter.LightEmission - 0.2
         BlasterP.ParticleEmitter.Transparency = NumberSequence.new(transp,transp)
         wait(0.1)
         transp = transp + 0.05
    end
end
 
 
local function checkEnable(player)
   
    if CheckSkill.Check(player,"Blaster") then
        Stuned = false
        print("Blastinngggg")
        P = player
        player.Character:WaitForChild("HumanoidRootPart").Anchored = true
        pureBlasterF(player)
    end
       
end
 
PureBlaster.OnServerEvent:Connect(checkEnable)
1 Like

Lerps aren’t really objectively better than tweens. They aren’t as smooth as tweens and don’t support EasingStyles. Regardless, it’s useful to learn how to use them, so it doesn’t really matter which is “better” I guess.

Now, what’s wrong with your code? What a Lerp does is take two Vector3s (or two CFrames) and find what’s x% (with x represented as a decimal between 0 and 1) of the way between the two. In your code, what you’re doing is setting the position and size to be 100% of the way from the start to your goal, which would be right at the goal. Not quite what you want, which is why it seems to teleport instantly to the final position.

How would you do this properly? Lerps are typically implemented through a loop, to set the alpha (that’s what we call the “x%” I mentioned earlier) to a different value at each incrementation of the loop. Since the position and size are constantly shifting, you’ll have to save what the original size and position were. Here’s what that might look like in your situation:

Changing this:

To something like this:

local timeToTake, alpha = 5, 0 -- the amount of time to take, and what the alpha starts at
local startSize, startCFrame = BlasterP.Size, BlasterP.CFrame
local goalSize = Vector3.new(100, 15, 15)
local goalCFrame = CFrame.new(startCFrame.X, 50, startCFrame.Z)

while alpha < 1 do

	BlasterP.CFrame = startCFrame:Lerp(goalCFrame, alpha)
	BlasterP.Size = startSize:Lerp(goalSize, alpha)
	-- increment alpha based on how long wait() takes so that it'll be 1 when `time` passes
	alpha = alpha + (wait() / timeToTake)
end

This is much more complicated than a tween, and it has little benefit over one here. Feel free to keep using tweens if you want, or to ask what something in my code does if it’s unclear.

11 Likes