function BuildModule:Build()
self.Building = true
self.StartPOS = {}
for i, part in self.Parts do
self.StartPOS[i] = part.CFrame
end
local partCount = #self.Parts
local segmentSize = 1 / partCount
self.ActiveBuilding = RunService.Heartbeat:Connect(function(dt)
if not self.Building then return end
self.ElapsedTime = math.min(self.ElapsedTime + dt, self.Duration)
local alpha = self.ElapsedTime / self.Duration
for index, part: Part in self.Parts do
if self.Building == false or self.ActiveBuilding == nil then return end
if self.StartPOS == {} then print("Finished") return end
if part.CFrame == self.GoalParts[index].CFrame then
table.remove(self.StartPOS, index)
continue
end
local goalPart = self.GoalParts[index]
local LocalAlpha = math.clamp(
(alpha - (index - 1) * segmentSize) / segmentSize,
0,
1
)
LocalAlpha = ease(LocalAlpha)
part.CFrame = self.StartPOS[index]:Lerp(goalPart.CFrame, LocalAlpha)
end
if self.ElapsedTime >= self.Duration then
self.Building = false
self.ActiveBuilding:Disconnect()
end
end)
end
OUTPUT:
ReplicatedStorage.BuildModule:45: attempt to index nil with 'Lerp'
