I am sizing a part with a script, and it ignores the pivot point

I am working on a device that adds water to an area, and more specifically, the preview of the area where the water is going to be added.

When the size attribute changes, the part changes size, but it ignores its pivot point to keep it on the ground, what can I possibly change to this line to solve this issue?

script.Parent.AttributeChanged:Connect(function()
	script.Parent.Zone.Size = script.Parent:GetAttribute("AreaSize")
end)
Here is an illustration describing what I want:

I think I remember in the docs for pivot points that they need to be repositioned after a scale operation.

How do I change the pivot point so it correctly fits when sized by script? (Sizing in studio makes the pivot change automatically)

maybe try to scale the pivot position by the same scale that is applied to the part. See what result that gives.

I cannot find a way to change the pivot position at all

Property CFrame BasePart.PivotOffset
Property CFrame Model.WorldPivot

See the above. Don’t worry, we’re writing up detailed documentation on pivots right now to have on the DevHub before we release pivots from beta.

4 Likes

Alternatively, you could experiment with some math:

local function resizeUpward(part,studs)
    local s = part.Size
    part.Size = Vector3.new(s.X,s.Y + studs,s.Z)
    part.CFrame *= CFrame.new(0,studs/2,0)
end

The preview just sized negatively somehow

It did not really get into negative numbers, it just sized down somehow

	resizeUpward(script.Parent.Zone, script.Parent.Zone.Size.Y - script.Parent:GetAttribute("AreaSize").Y/2)

I have messed a bit with the function code, turns out there is something about the CFrame division that is getting funky with how the preview goes up

Also also, it just keeps growing upwards each time I edit the zone value thing

If all you are wanting is for the preview to be on the ‘ground’ no matter what the scale, can you not just adjust its position to 1/2 of its size in the Y direction?

preview.cframe = cframe.new(x , y + (preview.size.y/2), z)
or something like that?

That just keeps adding to the height position every time the size is changed

Here’s what you want:

local function scaleCFrame(cframe, scale)
    local position = cframe.Position
    local rotation = cframe - position
    return rotation + position * scale
end
local oldPivot = part:GetPivot()
part.Size = part.Size * scale
part.PivotOffset = scaleCFrame(part.PivotOffset, scale)
part:PivotTo(oldPivot)
3 Likes

What exactly do I have to put in the scale?

image

Hold on a minute, roblox staff!?

Edit: Nothing is working and I am stressed, I need to know what to put in ‘Scale’

Well, it seems I have been stranded here.

1 Like

sadly there isnt any solution this is how roblox functions sadly i believe that they created this feature only for builders and not scripters