Only resize a part on an axis?

I need to resize a part only on the y and z axis via scripting, like:

workspace.PartToResize.Size.Y = 3 --3 is only a example

But it is not possible and i am getting the error: Y cannot be assigned to. So: Pls help. And here is no other way to solve my problem, i just need to resize my part on only one axis.

2 Likes

Vector3.X, and .Y, and .Z, are all read-only properties, you canā€™t mutate/set them to something. You just need to do

workspace.PartToResize.Size = Vector3.new(0, 3, 0)

But this canā€˜t work. I have a Mesh with Size Vector3.new(1,0,1), so if i only change, via your method, the X value for example, then the Y Size will automatically be changed from 0 to 0.05, and i NOT want this, else i have a result.

Well Size properties canā€™t have one of the components a 0, so they make it a 0.05 as a minimum. I donā€™t think that would cause issues, is there a reason why it bothers you? And I donā€™t think being able to set the components of the vector3 individually wouldā€™ve fixed it.

local size = workspace.PartToResize.Size
workspace.PartToResize.Size = Vector3.new(size.X, 3, size.Z)

You create a new Vector3 with the X and Z of the previous size, and set the Y to a new value

2 Likes

You canā€™t set INDIVIDUAL Values:

so rather just set all again with same values and ā€œYā€ being different

workspace.PartToResize.Size = Vector3.new(workspace.PartToResize.Size.X,3,workspace.PartToResize.Size.Z)
3 Likes

Iā€™m sorry if this question sounds silly, but isnā€™t that still useless? Letā€™s face it. Ok, Iā€™ll give you more information on my case/problem:
Iā€™m currently working on a way to upgrade my custom mesh importer. Pictures are better than words, so hereā€™s what I have now:

At first glance, it just looks normal, but hereā€™s the problem. If you look better, you see empty areas that are impossible to cover:
Bild
(Yellow square)

So I got the idea: Hey, why donā€™t you create a triangle mesh with length x, width Z and height 0? And this leads me to the current situation.

@starmaq why does it annoy me? Once again, a picture is better than words here:

And here you can clearly see the problem:
The thing I didnā€™t count with is that my TriangleMesh is stretching upwards. To form the triangles, which then connect the different vertices, I use EgoMoose 3DTriangelModules. So the code I am currently using is this one:

local wedge = script.TriangleMeshPart
local function draw3dTriangle(a, b, c, parent)
	local edges = {
		{longest = (c - a), other = (b - a), origin = a},
		{longest = (a - b), other = (c - b), origin = b},
		{longest = (b - c), other = (a - c), origin = c}
	};
	
	local edge = edges[1];
	for i = 2, #edges do
		if (edges[i].longest.magnitude > edge.longest.magnitude) then
			edge = edges[i];
		end
	end
	
	local theta = math.acos(edge.longest.unit:Dot(edge.other.unit));
	local w1 = math.cos(theta) * edge.other.magnitude;
	local w2 = edge.longest.magnitude - w1;
	local h = math.sin(theta) * edge.other.magnitude;
	
	local p1 = edge.origin + edge.other * 0.5;
	local p2 = edge.origin + edge.longest + (edge.other - edge.longest) * 0.5;
	
	local right = edge.longest:Cross(edge.other).unit;
	local up = right:Cross(edge.longest).unit;
	local back = edge.longest.unit;
	
	local cf1 = CFrame.new(
		p1.x, p1.y, p1.z,
		right.x, up.x, -back.x,
		right.y, up.y, -back.y,
		right.z, up.z, -back.z
	);
 
	local cf2 = CFrame.new(
		p2.x, p2.y, p2.z,
		-right.x, up.x, back.x,
		-right.y, up.y, back.y,
		-right.z, up.z, back.z
	);
	
	-- put it all together by creating the wedges
	
	local wedge1 = wedge:Clone();
	wedge1.Size = Vector3.new(0, h, w1); --SEE HERE
	wedge1.CFrame = cf1;
	wedge1.Parent = parent;
	
	local wedge2 = wedge:Clone();
	wedge2.Size = Vector3.new(0, h, w2);  --SEE HERE
	wedge2.CFrame = cf2;
	wedge2.Parent = parent;
end

Now the lines that give me problems are this one:
wedge1.Size = Vector3.new(0, h, w1);
and
wedge2.Size = Vector3.new(0, h, w2);

So I hope it was all the information you needed. With the module, you calculate where the triangle should be. It calculates not only its position, but also its size and changes the size of the triangle to get a perfect triangle between the 3 points. Real problem: In my case, if the angle of two faces of an imported mesh is over 90 degrees, this kind of empty space is created. To solve this problem, I have 2 kinds of solutions: The first would be to extend the relatively right side of the face by a few ā€œCentiStudsā€, not really the most ideal one, as there could be many other problems that I donā€™t really want to solve. The second would be to simply create a face with height 0, as it really is, which is the right solution. But there is only one wall left which blocks me and my goal: My mesh stretches when I change the height. When I import my triangle into Studio, the height is 0, but as soon as I change it via script, it becomes exactly above 0, which leads to my problem. Iā€™m not really the worldā€™s best explainer, so thereā€™s still something unclear, just ask.


Again, for those who don't understand anything yet: the size of my mesh needs to change, but as long as part of my size doesn't change. Later I'll try both of your methods, @Quoteory and @megatank58, hope it works (although I'm a bit sceptical).
1 Like

Try this:

 workspace.PartToResize.Size += Vector3.new(0, 3, 0)

That would add 3 to the size on the Y axis.

EDIT: I see that youā€™re wanting to set the Y, not add to it.

local size = workspace.PartToResize.Size
workspace.PartToResize.Size = Vector3.new(size.X, 3, size.Z)
2 Likes

o, i warned you guys:

Its NOT working, because size.X = 0 and 0 not works.

Hello Eternalove_fan32,
Iā€™ve found the solution.

Much like everyone else, the Size X,Y, and Z are Read-Only Properties.

So in order for you to resize your part you can do so by using a Vector3 and the script will allow you to keep the current size values for that part. Here it is:

game.workspace.MyPart.Size = Vector3.new(game.Workspace.MyPart.Size.X, game.Workspace.MyPart.Size.Y, game.Workspace.MyPart.Size.Z) -- This will keep the same size no matter what and change up the x,y,z values to however you need it.

Example:
game.workspace.MyPart.Size = Vector3.new(4, 5, game.Workspace.MyPart.Size.Z) -- this will keep Z the same and change the X and Y Values.

If this helped you please mark this as a solution thanks!

1 Like

I have an idea. Since the minimum part size is 0.05, you could move the part backwards by 0.025 studs (half of the size) using CFrame, so the top surface is at the correct position. Hope that made sense.

Thanks for trying, but its exactly what i tried. This method here not works. But at least you described the method for beginners, thx.


No really understand but okā€¦ what need i to do? Srry, but i not am understanding, as for me it not make sense. If i find the sense, maybe this will helpā€¦

Could you give an explanation on whats not working? Example the Output window? Because When I tried it it worked perfectly. Iā€™d love to help you out! :smiley:

1 Like

Ok, no Output Problem. If i now only position, but not resize the part, it works. If i now try to resize, my 0 value raise to 0.05. If i only touch one of the resizeball handles, same problem.

Thos is as you mesh is more than 0, so 0.05. I have a mesh with 0, and if i touch something from the size, it instantly raise to 0.05. If you want, i can link you the Mesh and actual code, the mesh is only a triangle so donā€˜t worry about copyright (rlly, you canā€˜t copyright a triangle, just like copyright copyright Water).

Hm, I donā€™t really know how meshes work yet (I just script) but im guessing itā€™s somewhere in the code that youā€™re messing up so yeah send me the code ill try to figure it out (only the resize and position part and not the entire script!)

1 Like

So I isolated the triangle generator script to understand the problem, and I told you, the code practically comes from the original code from EgoMoose, I already sent the link from the github. Ok, it comesā€¦

Or wait, I have an idea! Maybe for whichever value is changing to 0.05 when you use my Vector3 Method you can decrease the value by an extra 0.05? Maybe that will set it to 0 because 0.05 - 0.05 = 0?

You canā€™t decrease more than 0.05 and here is my script (fully automated, you will find all what you need):
TestScript.rbxm (6,7 KB)

But thanks to you all for you help and i hope we can fix this issue.

Alright! Let me check this out give me some time.

1 Like

Yeahhhhhhhhhhhhh. Idk what to do for this :confused: I dont understand this script its wayyy too complicated for me but as far as i can see your problem lies in the module? I dont understand anythign in it though so i cant figure that out im sorry but i tried. :confused:

Trignometry and all that is not my thing i dont know it yet lol

1 Like