Part resizing math issue

I’m currently attempting to make a sphere rapidly change its size randomly, but have run into an issue at the final required line of code, during a math… thing. (i do not know terminology)

whenever the code runs all steps are confirmed to be completed by a set of prints, but the error
“X cannot be assigned to -” appears. And i’m unsure of how to approach this.

the code


spawn(function()
	while true do
	wait(0.05)
	print("did a do")
		local xpmval = math.random(1,2)
		local xval = math.random(0.05,0.15)
		if xpmval == 1 then
			print("val1")
			if ball.Size.X <= 3 then	
				print("size up")		
				ball.Size.X = Vector3.new(ball.Size.X + xval)
						
			elseif xpmval == 2 then
				print("val2")
				if ball.Size >0.5 then
					print("size down")
					
				end
			end
		end
	end
end)

I haven’t been able to find any relevant topics on the devforum after a quick search, but if you know one that may have the answer (or you just know the answer) any help is appreciated.

thanks!

1 Like

You cannot assign to a specific size, you have to change the size itself.

ball.Size += Vector3.new(xval, 0, 0)
2 Likes

What line of your code does the Output window say the X can’t be assigned to?

Also how are you setting the ball.size.X variable in the script?
Is ball a Part Ball, a Mesh sphere, or a MeshPart sphere?

the error is at line 13

(i’m an idiot and have no clue what that second part means)

and it’s a part ball

the loop now runs multiple times, but the physical size of the sphere in the workspace remains the same

Oh, the ball’s size won’t increase unless all 3 sizes are added upon. Here you go:

ball.Size += Vector3.new(xval, xval, xval)
2 Likes

if ball.Size.X <= 3 then

You are referencing ball.Size.X. How are you setting what ball is?

As @Kaid3n22 said, try setting the size using all 3 values as (xval,xval,xval) since it’s a sphere.

1 Like

already swapped to that method, currently getting schooled on vector3’s lol.

kaiden has a good brain, unlike me

still not changing the size, see anything going wrong here?

local ball = script.Parent

spawn(function()
	while true do
	wait(0.05)
	print("did a do")
		local xpmval = math.random(1,2)
		local xval = math.random(0.05,0.15)
		local yval = math.random(0.05,0.15)
		local zval = math.random(0.05,0.15)
		if xpmval == 1 then
			print("val1")
			if ball.Size.X <= 3 then	
				print("size up")		
				ball.Size += Vector3.new(xval,yval,zval)
						
			elseif xpmval == 2 then
				print("val2")
				if ball.Size >0.5 then
					print("size down")
					
				end
			end
		end
	end
end)

It’s not like that with normal parts, but on spheres, it requires all 3 sizes to be added upon and cylinders require x and z to be added upon to change the width (y on a cylinder can make it change height without any extra requirements).

1 Like

If I had to say, it would be one of three reasons. One, the size increment is too small. Two, to properly change the size, the values need to be the same. Three, the size difference is too small to notice any change.

1 Like

You don’t need 3 variable random sizes, just one.
If you try 3 different random sizes only 1 will work, the Y value that @Kaid3n22 mentioned.

No, I meant the Y will only work for cylinders, the sphere needs all three.

2 Likes

Instead of using troubleshooting prints like print("val1") on that and other lines actually print the value with print(xpmval) to tell you what it is.

tried it out, the size increment does need to be at LEAST 0.5 studs / cycle to work

values only need to be the same with a part sphere, whereas mesh spheres can do single directions at a time.

thank you king!

now take this and continue that sigma grindset
:crown:

1 Like