Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with my growing brick script?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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
Ad
Log in to vote
0
Answered by 8 years ago

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!

Answer this question