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
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.
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
Use loops buddy
http://wiki.roblox.com/?title=Loops