Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I use CFrame:lerp() on welds correctly?

Asked by 6 years ago

So I made a script that is supposed to slide the "Slide" part of my gun to the "SlideStop" part:

Function Shoot()
local heartbeat = game:GetService("RunService").Heartbeat
local duration = 5
local alpha = 0
while alpha < 1 do 
    alpha = alpha + (heartbeat:wait() / duration) 
script.Parent.Slide.ManualWeld.C1 = script.Parent.Slide.ManualWeld.C1:lerp(script.Parent.SlideStop.CFrame,alpha)
    end
end

But when I run this function, the Slide Part lerps somewhere else and starts spazzing. What am I doing wrong?

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago

Define the CFrame you're lerping from outside of the loop

local heartbeat = game:GetService("RunService").Heartbeat;
local slideW = script.Parent.Slide.ManualWeld;
local slideStop = script.Parent.SlideStop;

function Shoot()
    local duration = 5
    local alpha = 0
    local start = slideW.C1;
    local stop = slideStop.CFrame;
    while alpha < 1 do 
        alpha = alpha + (heartbeat:Wait() / duration) 
        slideW.C1 = start:lerp(stop,alpha)
    end
end
Ad

Answer this question