#can someone explain why this lerp breaks

1 messages · Page 1 of 1 (latest)

rapid lichen
#
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'

slim verge
#

l...lerp?

#

Larp?

alpine cosmos
#

probably because u remove elements while iterating:

table.remove(self.StartPOS, index)

u should do that after the main loop or make main loop in reverse order and remove elements from end

rapid lichen
#

I might sound confusing