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?
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