local S=2.7 local I=16 local z={}local f={Attachment={scaledProps={Position="\086\101\099\116\111\114\051"}};BasePart={scaledProps={Size="\086\101\099\116\111\114\051"}},SpecialMesh={scaledProps={Scale="\086\101\099\116\111\114\051"}},Humanoid={scaledProps={WalkSpeed="\078\117\109\098\101\114";HipHeight="\078\117\109\098\101\114"},scaleFunc=function(S,I,z,f)if I=="\087\097\108\107\083\112\101\101\100"then return z*(f*.2)end return z*f end}}local function p(S,I,z)local f=Instance.new(S.."\086\097\108\117\101")f.Name=z or"\079\114\105\103\105\110\097\108\095"..S f.Value=I return f end local function y(S,I)for S,z in pairs(S:GetDescendants())do for S,f in pairs(f)do if z:IsA(S)then for S,p in pairs(f.scaledProps)do I(z,S,p,f)end end end end end function z.configureRig(S)y(S,function(S,I,z)local f=p(z,S[I],"\079\114\105\103\105\110\097\108\095"..I)f.Parent=S end)local I=S:FindFirstChild("\072\117\109\097\110\111\105\100")if I then I:BuildRigFromAttachments()end end function z.rescaleRig(S,I)for S,I in pairs(S:GetDescendants())do if I:IsA("\077\111\116\111\114\054\068")then I:Destroy()end end y(S,function(S,z,f,p)local y=S:FindFirstChild("\079\114\105\103\105\110\097\108\095"..z)if y then if p.scaleFunc then S[z]=p.scaleFunc(S,z,y.Value,I)else S[z]=y.Value*I end end end)local z=S:FindFirstChild("\072\117\109\097\110\111\105\100")if z then z:BuildRigFromAttachments()end end return z
local HIP_HEIGHT = 2.7
local WALK_SPEED = 16

local RigUtil = {}

local scalables = {
    Attachment = {
        scaledProps = {
            Position = "Vector3",
        },
    },
    BasePart = {
        scaledProps = {
            Size = "Vector3",
        },
    },
    SpecialMesh = {
        scaledProps = {
            Scale = "Vector3",
        },
    },
    Humanoid = {
        scaledProps = {
            WalkSpeed = "Number",
            HipHeight = "Number",
        },
        scaleFunc = (function(obj,prop,orig,newScale)
            if prop == "WalkSpeed" then
                return orig*(newScale*0.2)
            end
            return orig*newScale
        end),
    }
}

local function newValue(type,value,name)
    local valueobj = Instance.new(type.."Value")
    valueobj.Name = name or "Original_"..type
    valueobj.Value = value
    return valueobj
end

local function forEachScalable(rig, func)
    for _,obj in pairs(rig:GetDescendants()) do
        for type,typeStruct in pairs(scalables) do
            if obj:IsA(type) then
                for propName,valueType in pairs(typeStruct.scaledProps) do
                    func(obj,propName,valueType,typeStruct)
                end
            end
        end
    end
end

function RigUtil.configureRig(rig)

    -- create original property tags
    forEachScalable(rig, function(obj,propName,valueType)
        local origValue = newValue(valueType,obj[propName],"Original_"..propName)

        origValue.Parent = obj
    end)

    -- build the rig
    local humanoid = rig:FindFirstChild("Humanoid")

    if humanoid then
        humanoid:BuildRigFromAttachments()
    end
end

function RigUtil.rescaleRig(rig,newScale)
    for _,obj in pairs(rig:GetDescendants()) do
        -- destroy motors
        if obj:IsA("Motor6D") then
            obj:Destroy()
        end
    end

    -- set based on original props and scale
    forEachScalable(rig, function(obj,propName,valueType,typeStruct)
        local origValue = obj:FindFirstChild("Original_"..propName)

        if origValue then
            -- if there's a special reducer use it
            if typeStruct.scaleFunc then
                obj[propName] = typeStruct.scaleFunc(obj,propName,origValue.Value,newScale)
            else
                obj[propName] = origValue.Value * newScale
            end
        end
    end)

    local humanoid = rig:FindFirstChild("Humanoid")

    if humanoid then
        humanoid:BuildRigFromAttachments()
    end
end

return RigUtil