How to make the part expand itself

So, what I have been trying to do is to create the part that expands itself until it hits to the specific size where it needs to stop and reset to the original size. Here is the script I have right now.

script.Parent.Size = Vector3.new(13,13,13)
if script.Parent.Size > Vector3.new(30,30,30) then
	script.Parent.Size = Vector3.new(13,13,13)
	script.Enabled = false
else
	script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1)
end

I made this myself and I really dont know the error so if you figure it out please tell me.
Thanks!

You need a Intro to For Loops | Roblox Creator Documentation for this to happen.
If you want it to keep happening continuously then a while true do loop will be needed.

1 Like

If you want the object to expand smoothly, I’d also recommend checking out Tweens, which can easily be used to do that:

Here is an example of tweening if you want the part to get bigger smoothly, you can set the target size to the size you want it to stop getting bigger at.

-- get a reference to the part you want to tween
local part = workspace.Part

-- set the target size you want the part to tween to
local targetSize = Vector3.new(2, 4, 1)

-- set the duration of the tween in seconds
local tweenDuration = 2

-- create the TweenInfo object with the desired duration and easing style
local tweenInfo = TweenInfo.new(tweenDuration, Enum.EasingStyle.Linear, Enum.EasingStyle.Out)

-- create the tween using TweenService:Create
local partTween = game:GetService("TweenService"):Create(part, tweenInfo, {Size = targetSize})

-- start the tween using Tween:Play
partTween:Play()
task.wait(4) -- so I can see it happen
---------------------------
-- A bit choppy
script.Parent.Size = Vector3.new(13,13,13)
if script.Parent.Size.X > 30 then
	script.Parent.Size = Vector3.new(13,13,13)
--	script.Enabled = false
else 
	for s = 13, 29 do task.wait(0.1)
		script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1)
	end
end

So …

task.wait(4) -- so I can see it happen
---------------------------
-- smooth as glass
local ts = game:GetService("TweenService")
script.Parent.Size = Vector3.new(13, 13, 13)
function sizer(obj, _time, scale)
	local info = TweenInfo.new(_time, Enum.EasingStyle.Sine,Enum.EasingDirection.InOut, 0, false, 0)
	local size = {Size = Vector3.new(scale, scale, scale)}
	local tween = ts:Create(obj, info, size)
	tween:Play() 
end

sizer(script.Parent, 10, 30)
-- the 10 is time it takes, 30 is new size 

Wanted you to know that input was time. But “time” is also a command, so I used _time in the function.

Since none of the posts directly pointed out the problem in your code, it’s that you cannot compare a Vector3 except = or ~=. You need to use:

script.Parent.Size.Magnitude > (Vector3.one*30).Magnitude

instead.

local tweenService = game:GetService("TweenService")

local part = script.Parent

part.Size = Vector3.new(13,13,13)

tweenService:Create(
	part, -- instance
	TweenInfo.new(
		2, -- speed
		Enum.EasingStyle.Linear, -- style
		Enum.EasingDirection.In, -- direction
		0, -- repeat
		false, -- boolean (reverse)
		0 -- delay
	),
	{Size = Vector3.new(30, 30, 30)} 
	-- properties.. {Size = Vector3.new(30, 30, 30), Position = ..}
):Play()

Nice … I was thinking he wanted it to grow … as for your error that is there.
That’s why I used … if script.Parent.Size.X > 30 then
Just checking one value in the Vector3.

That works too, but if not all values in the size are consistent they might run into issues.

Thanks for all of the comments, I will begin testing each one of the script to see if it works, starting from simple to complicated changes.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.