How can I make a BasePart smaller in the right proportion, with script?

https://gyazo.com/7942f4c45188a07eed55eb499a5e4bee

I can shrink or enlarge this meshpart, but how can I do it with a script? at the right rate?

1 Like

You mean just enlarging it right?

I think…

local MeshP = (location here)
MeshP.Size.x = (...) -- the size should be the current size times an amount.
MeshP.Size.y = (...)
MeshP.Size.z = (...)

I’m new to scripting, so if it doesn’t work, eh… well…

1 Like

Size.X/Y/Z is just values, you can’t change them. You should do

MeshP.Size = Vector3.new(x,y,z)
1 Like

I am pretty sure it is not the (current size * amount) but rather setting the size to the given value.
You can simply set it like Vector3.new(x , y, z) which will save us time and also lines of code.
Your method is absolutely correct but why do it the harder way

3 Likes

You cannot do this currently with Models or Unions, but only normal parts and meshparts

I think Meshes can stretch freely - but to do this with a script to a Part in general you need to change the Size in the X/Z coordinate and then offset the Position by half that amount the size has changed to give the illusion of resizing.

local p = workspace.SpawnLocation
local rate = 1
for i = 1,10 do
	wait(0.5)
	p.Size -= Vector3.new(rate,0,0)
	p.Position -= Vector3.new(rate/2,0,0)
end

You can also do this smoothly using TweenService

local p = workspace.SpawnLocation
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,true)
local oS = p.Size
local oP = p.Position
local tp = {
	Size = Vector3.new(oS.X/2, oS.Y, oS.Z),
	Position = Vector3.new(oP.X - oS.X/4, oP.Y, oP.Z)
}

ts:Create(p,ti,tp):Play()

You can make the mesh part’s size larger or smaller the same way you do it with a regular basepart .
Instance.Size = Vector3.new(x , y , z)

I already know that, bro how I can know correct x y z ?

my purpose is not to make animations or tweenservice or something

Correct (X,Y,Z)?
If you want the correct size just adjust it to your liking.

I think you can simply multiply the Vector 3 Size property, and that’ll keep the proportions.

Example:

myPart.Size = myPart.Size * 2 --Make it 2 times larger
myPart.Size = myPart.Size * 0.5 -- Make it 2 times smaller

yes, but it didn’t work exactly as I wanted, it doesn’t shrink at the same rate as the video I showed
I won’t accept this as an answer because it’s not exactly what I want, but I’ll use it for now

Thanks :slight_smile:

You can adjust the number you multiply with until you reach the rate you’d like.

try what i did in this video, the proportions are not the same
(Video is on Top)

If you want to increase it by the same rate every time, that is definitely possible using the same method:

With a bit of math I’ve managed to get an equation that’ll get you the right proportion.

local function findProportionalRateFromAxis(part, axis, rate)
	return (part.Size[axis]+rate)/part.Size[axis] --Find how much you need to multiply with in order to reach that on the axis.
end

yourPart.Size = yourPart.Size * findProportionalRateFromAxis(yourPart, "X", 1) --Increase it by 1 stud to the X, with proportions

image
You’ll get an increase similar to this ^
Demonstration: