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
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") end local OriginalXDirection = model:GetAttribute("OriginalXDirection") if OriginalXDirection == nil then model:GetAttribute("OriginalXDirection", cf.XVector) OriginalXDirection = model:GetAttribute("OriginalXDirection") end local OriginalYDirection = model:GetAttribute("OriginalYDirection") if OriginalYDirection == nil then model:GetAttribute("OriginalYDirection", cf.YVector) OriginalYDirection = model:GetAttribute("OriginalYDirection") end local OriginalZDirection = model:GetAttribute("OriginalZDirection") if OriginalZDirection == nil then model:GetAttribute("OriginalZDirection", cf.ZVector) OriginalZDirection = model:GetAttribute("OriginalZDirection") end local originalCFrame = CFrame.fromMatrix(OriginalPosition, OriginalXDirection, OriginalYDirection, OriginalZDirection) local scale = Vector3.new(xScale, 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 obj:GetAttribute("OriginalSize", Vector.zero) elseif obj:IsA("SpecialMesh") then obj:GetAttribute("OriginalSize", obj.Scale) end OriginalSize = obj:GetAttribute("OriginalSize") end 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 else DontScale = true end end 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 = (CFrame.new(origin + 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.new(c0NewPos)*CFrame.Angles(c0RotX, c0RotY, c0RotZ) obj.C1 = CFrame.new(c1NewPos)*CFrame.Angles(c1RotX, c1RotY, c1RotZ) elseif obj:IsA("SpecialMesh") then local newScale = OriginalSize * scale obj.Scale = newScale end end end return model end