qPerfectionWeld 2.0

Yeah, the explicit : Instance is technically redundant, but it keeps the type checker happy when this module is reused in different contexts. Also not sure why you’re pointing out ipairs, it’s standard practice for arrays, still used in Roblox’s own code, and the difference is negligible for a script like this.

1 DestroyAttachedJoints vs GetJoints()

GetJoints() does exist, but it’s the wrong tool here:

  • GetJoints() allocates a new Lua table every single call, adding extra GC pressure if repeatedly used in loops.
    Using :GetChildren() allocates only once per call, meaning fewer allocations overall and lighter GC overhead during iteration.
  • it only returns joints that actively connect this part to something else, so it can miss loose Motor6Ds, unused welds, and other orphaned JointInstances sitting under the part

iterating the children and nuking every JointInstance is both faster and future-proof.


2 if scope:IsA("Model") then …

Inside the if, Luau temporarily treats scope as a Model. Once you exit that block, scope reverts to Instance, so you lose direct access to properties like PrimaryPart. Storing it as:

local model = scope :: Model

keeps the narrowed type for the rest of the function, avoids extra casts, and makes the intent obvious to anyone reading the code.

Appreciate you taking notes :slightly_smiling_face: keep at it

1 Like