#Tool CFrame Scaling (w/ Welds)

1 messages · Page 1 of 1 (latest)

versed gull
#

I am having trouble positioning all evenly random sized parts with welds in a tool. As seen in the images provided, the parts are incorrectly positioned the more they are scaled. All parts are unanchored, noncollidable, and massless. The following code shown is a small part from my InventoryService module script:

local foundTool = assets.Crops:FindFirstChild(fruitName)
if foundTool then
    local toolClone: Tool = foundTool:Clone()
    toolClone.Name = itemData
    toolClone:SetAttribute("FruitID", toolName)
    toolClone:SetAttribute("IsFruit", true)
                        
    for _, part in ipairs(toolClone:GetDescendants()) do
        if part:IsA("BasePart") then
            part.Size *= weight
                                
            local mesh = part:FindFirstChildWhichIsA("SpecialMesh")
            if mesh then
                mesh.Scale *= weight
            end
        end
    end

    local function scaleCFrame(cf, scaleFactor)
        local pos, rot = cf.Position, cf - cf.Position
        return CFrame.new(pos * scaleFactor) * rot
    end
    for _, weld in ipairs(toolClone:GetDescendants()) do
        if weld:IsA("Weld") or weld:IsA("Motor6D") then
            weld.C0 = scaleCFrame(weld.C0, weight)
            weld.C1 = scaleCFrame(weld.C1, weight)
        end
    end
    if toolClone:FindFirstChild("Handle") then
        local modelTemplate = assets.Plants[fruitName]["ClientModel"]
        if modelTemplate then
            local _, size = modelTemplate:GetBoundingBox()
            local longestAxis = math.max(size.X, size.Y, size.Z)
            toolClone.GripPos = Vector3.new(0, 0, longestAxis * 0.125)
        end
    end
                        
    toolClone.Parent = player.Backpack
end
magic pierBOT
#

studio** You are now Level 1! **studio

worn ginkgo
magic pierBOT
#

studio** You are now Level 7! **studio

stable vortex
#

I usual Union all the part into in singular in object scale in works place

cinder yoke
#

You can use
Size = 1
part:ScaleTo(Size *= weight)