Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with my growing brick script?

No error, but it doesn't work for me.

while wait(0.1) do
	if script.Parent.Size == Vector3.new(100, 10, 100) then
		script.Parent.Size = script.Parent.Size + Vector3.new(0, - 0.1, 0)
	end
	
	if script.Parent.Size == Vector3.new(100, 9, 100) then
		script.Parent.Size = script.Parent.Size + Vector3.new(0, 0.1, 0)
	end
end

2 answers

Your problem is that when you use the if statement inside the while loop it executes it once, because the next time it goes to the beginning of the loop the size wouldn't be (100,10,100) or (100,9,100). It's size would go to (100,9.9,100) if the first if statement was executed, and if the second if statement was executed then it'd be (100,9.1, 100). So after the first time, the size isn't the same anymore and the if statements won't run if it's not equal to.

I'd do this:

while wait(0.1) do
    if script.Parent.Size == Vector3.new(100, 10, 100) then
	for _ = 1,10 do
		wait(0.1)
        	script.Parent.Size = script.Parent.Size - Vector3.new(0, -0.1, 0)
	end
    end

    if script.Parent.Size == Vector3.new(100, 9, 100) then
	for_ = 1, 10 do
		wait(0.1)
        	script.Parent.Size = script.Parent.Size + Vector3.new(0, 0.1, 0)
	end
    end
end

Try:

part = script.Parent;
while wait(0.1) do
    if script.Parent.Size == Vector3.new(100, 10, 100) then
        script.Parent.Size = Vector3.new(part.Size.x, part.Size.y - 0.1, part.Size.z);
    end

    if script.Parent.Size == Vector3.new(100, 9, 100) then
        script.Parent.Size = Vector3.new(part.Size.x, part.Size.y + 0.1, part.Size.z);
    end
end

Not sure if you can just set the individual values like:

part.Size.x = 30;

You're free to try though, might be easier.

Also, if you're trying to SHRINK your brick and then GROW it back up again, you need to use a for loop:

part = script.Parent;
while wait(0.1) do
    for i = 10, 9, -.1 do
        if script.Parent.Size == Vector3.new(100, 10, 100) then
            script.Parent.Size = Vector3.new(part.Size.x, i, part.Size.z);
        end
        wait(.1);
    end
   
    for i = 9, .1, 1 do
       if script.Parent.Size == Vector3.new(100, 9, 100) then
            script.Parent.Size = Vector3.new(part.Size.x, i, part.Size.z);
        end
        wait(.1);
    end
end

Hope this helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.