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

Gradual part resize script?

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

✓ Accepted answer

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.

2 comments

0

You can add to any value here, why just X?

0

This was just to fit the question, but yes you can use any Vector3 object.

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.

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

1 comment

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?

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