How to store size of part in a variable?

This code does not work:

local part = script.Parent
local size = part.Size
wait(5)
while wait() do
	size = Vector3.new(size.X + 1, size.Y + 1, size.Z + 1)	
end

But this one does:

local part = script.Parent
wait(5)
while wait() do
	part.Size = Vector3.new(part.Size.X + 1, part.Size.Y + 1, part.Size.Z + 1)	
end

The second one looks ugly, so how do I store “part.Size” in a variable?

In your first example, the Size property is passed and assigned to your variable by value. Meaning, the current value of the Size property is stored, and when it changes, the size the variable stores will not change with it. So when you assign a new value to the size variable, you’re expecting it to affect the actual part’s size, but rather, it’s just assigning a new Vector3 to the variable that you have. So in theory, it doesn’t work, but it actually is doing what it’s supposed to do. Hopefully this makes a bit of sense.

local part = script.Parent
local size = part.Size

while task.wait() do
	size = part.Size
	part.Size = Vector3.new(size.X + 1, size.Y + 1, size.Z + 1)
end

Redefine size every loop

Like @C_Sharper touched upon, you would need to redefine the size variable within the loop, not outside of it.

Here is what you are trying to achieve:

local part = script.Parent
wait(5)
while wait() do
	local size = part.Size
	Part.Size = Vector3.new(size.X + 1, size.Y + 1, size.Z + 1)	
end
local part = script.Parent
task.wait(5)
while task.wait() do
	part.Size += Vector3.new(1, 1, 1)
end

You should be opting to use “task.wait()” instead of “wait”, don’t forget about compound operators (they work with Vector3 values too).

the first one does actually store the size of the part in the size variable. It’s just that you can’t change the size of part as a variable. Setting size to those numbers will only change size to those numbers and not part.Size