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

how to make a part expand in all directions?

my current script is this

local xValue = 20
local part = script.Parent

while wait(.05) do
	part.Size = Vector3.new(xValue, 1, 1)
	xValue = xValue + 0.5
	
	if xValue >= 40 then
		break
	end 
end

im new to scripting so dont make anything too complicated, all it does is expand in one direction and i want it to expand in all directions so i can use it in explosions example: https://youtu.be/9tBoj7FE6-g

3 answers

you can just add to the part's size every iteration, there's no need to increment a variable separately

local increment = Vector3.new(0.5, 0.5, 0.5) -- you can specify how quickly each axis grows individually

while true do
	part.Size += increment -- compound ops winning
	wait(0.05) -- using while wait(n) do usually isn't recommended since it abuses how truthy values work
end

i'm not sure what exactly you need this for, but TweenService might be a viable alternative, so you should look into it

You create a variable and store the vector 3 size of the part in it. Next, you create a new size by multiplying the currentSize by the speed of growth you want. Finally you want to divide that part by it's previous size.

Using this method, all you have to change to increase the speed at which you want the part to grow at is changing the growthSpeed variable.

To make the size increase smoothly, you could use tween service.

local part = script.Parent
-- Configs
local waitTime = 0.1
local growthSpeed = 1.1

while wait(waitTime) do
	local currentSize = Vector3.new(part.Size.X,part.Size.Y,part.Size.Z)
	local newSize = (Vector3.new(part.Size.X,part.Size.Y,part.Size.Z) * growthSpeed) / currentSize
	part.Size = currentSize + newSize
end

1 comment

0

Also, to make the part growing in size smoother, you could add tween service so it tweens the current size to the new size.

Make sure to view source before using this script. How this script works is told in comments. TimeInSeconds is how much the script will wait before making the block grow. IncrementToGrow to grow is how many studs in all directions the block will grow. SizeToBreak is the size the part must be before the loop is broken. The while true do loop keeps running until it is broken


--Defines the Part
local part = script.Parent
--Edit these!

local TimeInSeconds = 1 -- How many seconds should the script wait before making the ball grow again? Set to value higher than 0. Otherwise script will crash.

local IncrementToGrow = 1 -- How many studs the part will grow per cycle

local SizeToBreak = 40 -- To what size you want the ball to grow before the script stops running

--This part will work automatically with the things edited above!
local Increment = Vector3.new(IncrementToGrow,IncrementToGrow,IncrementToGrow) 
--[Loop]--
while true do
	part.Size = part.Size + Increment
	wait(TimeInSeconds)
	if script.Parent.Size == Vector3.new(SizeToBreak,SizeToBreak,SizeToBreak) then
		break
	end
end

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