Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.