diff --git a/UniversalAutoload.lua b/UniversalAutoload.lua index a2a40c6..34ed246 100644 --- a/UniversalAutoload.lua +++ b/UniversalAutoload.lua @@ -2585,32 +2585,37 @@ function UniversalAutoload:doUpdate(dt, isActiveForInput, isActiveForInputIgnore spec.customOffset = spec.customOffset or 0 spec.customRotation = spec.customRotation or 0 - local rotationshift = spec.loadVolume.length / 3 - local direction = (spec.currentTipside == "right") and 1 or -1 - local function clampOffset() - local minOffset = (spec.customRotation == 0) and 0 or rotationshift - local maxOffset = spec.loadVolume.length / 2 + minOffset - spec.customOffset = math.clamp(spec.customOffset, minOffset, maxOffset) - end + -- spec.loadVolume is only populated server-side by initialiseTransformGroups, + -- or for vehicles without a valid loadArea config. Skip the shift/rotate logic + -- in those cases to avoid "attempt to index nil with 'length'". + if spec.loadVolume then + local rotationshift = spec.loadVolume.length / 3 + local direction = (spec.currentTipside == "right") and 1 or -1 + local function clampOffset() + local minOffset = (spec.customRotation == 0) and 0 or rotationshift + local maxOffset = spec.loadVolume.length / 2 + minOffset + spec.customOffset = math.clamp(spec.customOffset, minOffset, maxOffset) + end - if spec.leftKeyPressed then - spec.customOffset = spec.customOffset - (UniversalAutoload.SHIFT_DELTA * direction) - clampOffset() - end + if spec.leftKeyPressed then + spec.customOffset = spec.customOffset - (UniversalAutoload.SHIFT_DELTA * direction) + clampOffset() + end - if spec.rightKeyPressed then - spec.customOffset = spec.customOffset + (UniversalAutoload.SHIFT_DELTA * direction) - clampOffset() - end + if spec.rightKeyPressed then + spec.customOffset = spec.customOffset + (UniversalAutoload.SHIFT_DELTA * direction) + clampOffset() + end - if spec.rotateKeyPressed then - local rotated = spec.customRotation ~= 0 + if spec.rotateKeyPressed then + local rotated = spec.customRotation ~= 0 - spec.customRotation = rotated and 0 or -math.pi / 2 - spec.customOffset = spec.customOffset + (rotated and -rotationshift or rotationshift) + spec.customRotation = rotated and 0 or -math.pi / 2 + spec.customOffset = spec.customOffset + (rotated and -rotationshift or rotationshift) - spec.rotateKeyPressed = false - clampOffset() + spec.rotateKeyPressed = false + clampOffset() + end end end