#How to Scale accessory along with bodyparts

1 messages · Page 1 of 1 (latest)

safe oyster
#

`local Scale = {}
Scale.__index = Scale

function Scale.new(character)
local self = setmetatable({}, Scale)
self.character = character
return self
end

local function getModelCenter(model)
local total = Vector3.new(0, 0, 0)
local count = 0
for _, part in model:GetDescendants() do
if part:IsA("BasePart") then
total += part.Position
count += 1
end
end
return count > 0 and (total / count) or Vector3.new(0, 0, 0)
end

function Scale:IncreaseSize()
local weight = self.character.Parent:WaitForChild("Weight")
local factor = weight.Value
local center = getModelCenter(self.character)

for _, obj in self.character:GetDescendants() do
    if obj:IsA("BasePart") then
        obj.Size = obj.Size * factor
        
        local offset = obj.Position - center
        obj.Position = center + (offset * factor)
        
        for _, att in obj:GetChildren() do
            if att:IsA("Attachment") then
                att.Position = att.Position * factor
            end
        end
        
    elseif obj:IsA("Accessory") then
        local handle = obj:FindFirstChild("Handle")
        if handle and handle:IsA("BasePart") then
            handle.Size = handle.Size * factor
            
            for _, att in ipairs(handle:GetChildren()) do
                if att:IsA("Attachment") then
                    att.Position = att.Position * factor
                end
            end
            
            local mesh = handle:FindFirstChildOfClass("SpecialMesh")
            if mesh then
                mesh.Scale = mesh.Scale * factor
            end
        end
    end
end

end

return Scale`

#

So it scales the BodyPart evenly but the Accessory is stuck in place

spiral dagger
#

there's this function on models called
":ScaleTo()"

#

it should auto scale the accessories too