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

Gradual part resize script?

Asked by
Jiptix 2
7 years ago

So, I am trying to write a script where the script's parent gradually grows or gets smaller. I have something that works, but I know there has to be an easier way to do this. (It is something where you do + or something.) Anyway, here is what I am currently using:

script.Parent.Size = Vector3.new(20, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(21, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(22, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(23, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(24, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(25, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(26, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(27, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(28, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(29, 1, 80)
wait(.05)
script.Parent.Size = Vector3.new(30, 1, 80)

Instead of me having to go in one by one changing the x, y, or z values, is there a way where I can just say something like "+1" and it adds 1 to whatever the current X value is? Thanks

4 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

As udayk8139 has said, you should be using a loop. But it is possible to add only the x value. Vector3 Operators

Example:-

local part = script.Parent

for i=1, 10 do -- loop
    part.Size = part.Size + Vector3.new(1,0,0) -- add one to the existing vector3
    wait(0.05)
end

I hope this helps.

0
You can add to any value here, why just X? P100D 590 — 7y
0
This was just to fit the question, but yes you can use any Vector3 object. User#5423 17 — 7y
Ad
Log in to vote
0
Answered by
P100D 590 Moderation Voter
7 years ago

While a lot of the questions are correct and can be used, I would personally recommend using Vector3:Lerp. This helps achieve much smoother movement and is overall a better idea. An example of how to implement this would be:

--Assuming part is already defined
local originalSize = part.Size
local targetSize = Vector3.new(20, 1, 5)
for i = 1, 10 do
    part.Size = originalSize:Lerp(targetSize, i/10)
    wait(0.1)
end

This would smoothly transition the size of the part over the course of a second.

Log in to vote
-1
Answered by
Master_JJ 229 Moderation Voter
7 years ago

A way to do this is to make a variable for the x value, and add one to it in the loop.

local xValue = 20
local part = script.Parent

while wait(.5) do
    part.Size = Vector3.new(xValue, 1, 80)
    xValue = xValue + 1
end

First we define xValue as 20 and we define the part.

Then we create an Endless loop, that runs every .5 seconds. We set the xValue of the part size to that number, and add one to the number, so next time we size it, the number will be greater by 1.

If you don't want this to be an endless loop, do the following.

local xValue = 20
local part = script.Parent

while wait(.5) do
    part.Size = Vector3.new(xValue, 1, 80)
    xValue = xValue + 1

    if xValue >= 40 then -- Change 40 to the number you want the increase to stop at.
        break -- Breaks out of loop
    end 
end
Log in to vote
-4
Answered by 7 years ago

Please provide code with your answers. Simply posting an explanation does not help someone new to programming understand how to implement a concept programatically.

Use loops buddy

http://wiki.roblox.com/?title=Loops

0
@Admins : 1 - He doesn't know how to use loops, in such case giving a guide to let him understand the basics is more helpful than simply posting a damn answer "trying" to make it understandable. What's the use of simply telling the how the script should be done when they don't know what loops are? buoyantair 123 — 7y

Answer this question