Log in to vote

Resizing a model or a part changes the PivotPoint in-game?

Asked by 1 month ago

So anyways I have a script where players can resize their model

now the problem I have is that because resizing changes the pivot point

whenever I use :GetPivot() onto their model whenever they drag

the pivot changes so basically if they resize like 5 upwards on the y axis

everytime they try to pivot it its like 5 studs upwards on the y axis

so I was wondering if there was a way to stop this from happening

and No I do not want any answers that make me use SetPrimaryPartCFrame or all the other deprecated functions

1 answer

Log in to vote
Answered by 1 month ago
Edited 1 month ago

I'm assuming you're using my answer from the previous question. Sadly, you can't change model's pivot offset. However, if you want to get the original pivot, you can create the attributes OriginalPosition, OriginalXDirection, OriginalYDirection, and OriginalZDirection in the model since a pivot (aka CFrame) has a position and a direction. To get the CFrame from position and direction, use CFrame.fromMatrix(position, xDirection, yDirection, zDirection).

function ScaleModel(model: Model, xScale: number, yScale: number, zScale: number): Model
    local cf, _ = model:GetBoundingBox()
    local origin = cf.Position

    local OriginalPosition = model:GetAttribute("OriginalPosition")
    if OriginalPosition == nil then
        model:GetAttribute("OriginalPosition", origin)
        OriginalPosition = model:GetAttribute("OriginalPosition")
    local OriginalXDirection = model:GetAttribute("OriginalXDirection")
    if OriginalXDirection == nil then
        model:GetAttribute("OriginalXDirection", cf.XVector)
        OriginalXDirection = model:GetAttribute("OriginalXDirection")
    local OriginalYDirection = model:GetAttribute("OriginalYDirection")
    if OriginalYDirection == nil then
        model:GetAttribute("OriginalYDirection", cf.YVector)
        OriginalYDirection = model:GetAttribute("OriginalYDirection")
    local OriginalZDirection = model:GetAttribute("OriginalZDirection")
    if OriginalZDirection == nil then
        model:GetAttribute("OriginalZDirection", cf.ZVector)
        OriginalZDirection = model:GetAttribute("OriginalZDirection")

    local originalCFrame = CFrame.fromMatrix(OriginalPosition, OriginalXDirection, OriginalYDirection, OriginalZDirection)

    local scale =, yScale, zScale)

    for _, obj in pairs(model:GetDescendants()) do
        local OriginalSize = obj:GetAttribute("OriginalSize")
        if OriginalSize == nil then
            if obj:IsA("BasePart") then
                obj:GetAttribute("OriginalSize", obj.Size)
            elseif obj:IsA("JointInstance") then
            elseif obj:IsA("SpecialMesh") then
                obj:GetAttribute("OriginalSize", obj.Scale)
            OriginalSize = obj:GetAttribute("OriginalSize")

        local DontScale = obj:GetAttribute("DontScale")
        if DontScale == nil then
            if obj:IsA("BasePart") or obj:IsA("SpecialMesh") then
                obj:SetAttribute("DontScale", false)
                DontScale = obj:GetAttribute("DontScale")
            elseif obj:IsA("JointInstance") then
                DontScale = false
                DontScale = true

        if DontScale == false then
            if obj:IsA("BasePart") then
                local newSize = OriginalSize * scale
                obj.Size = newSize

                local distance = (obj.Position - origin)
                local rotation = (obj.CFrame - obj.Position)
                obj.CFrame = ( + distance*scale) * rotation)
            elseif obj:IsA("JointInstance") then
                local c0NewPos = obj.C0.p*scale
                local c0RotX, c0RotY, c0RotZ = obj.C0:ToEulerAnglesXYZ()

                local c1NewPos = obj.C1.p*scale
                local c1RotX, c1RotY, c1RotZ = obj.C1:ToEulerAnglesXYZ()

                obj.C0 =*CFrame.Angles(c0RotX, c0RotY, c0RotZ)
                obj.C1 =*CFrame.Angles(c1RotX, c1RotY, c1RotZ)
            elseif obj:IsA("SpecialMesh") then
                local newScale = OriginalSize * scale
                obj.Scale = newScale
    return model
I figured it out, all I had to do was reset the PivotPoint back to the center every single time I moved it but anyways this works too thanks for answering my questions. Overseer_Prince 188 — 1mo
Also the Model:ScaleTo() function you had mentioned, I have checked it out and I think that functions scales models on 3 axis and it does not give you any options to resize on a single axis. I know this because theres only one parameter that accepts a number so I shouldn't be that excited for that function Overseer_Prince 188 — 1mo
It's not like that. If you want to scale a model to, 50, 50) you can do model:ScaleTo(50) T3_MasterGamer 2142 — 1mo
And also, you said that "whenever the model scales 5 upwards y axis, pivot also moves 5 upwards y axis" so i thought you were trying to get the previous pivot T3_MasterGamer 2142 — 1mo

Answer this question