Tween a parts size in one direction

Hello there, pretty much, I want to make a shutter which slides down and down only. When I change the size, it goes all weird and uneven. And I know that you have to change the position, but I can’t be bothered changing the position for every single part.

I was wondering if there was a more efficient way to do this, help would be appreciated. :sunglasses:

Do you have to set the position manually like that? Is there no way to make it so the script automatically divides the position in 2 for you?

There’s Part:Resize but it won’t work for tweening. You could write a method that does the math for you

local tweenService = game:GetService("TweenService")

local function CreateResizeTween(instance, tweenInfo, normalId, deltaAmount)
  local delta = Vector3.fromNormalId(normalId) * deltaAmount
  return TweenService:Create(instance, tweenInfo, { Size = part.Size + delta, Position = part.Position + delta / 2 })
end

You’d use that in place of TweenService:Create

1 Like

Is CreateResize supposed to be a function? And also, what is delta supposed to mean. It’s a little confusing to me, sorry.

Sorry yeah I missed the function, fixed.

delta is just a variable I use in the return line

You’d basically call this function with all the right parameters, instead of where you’d usually call TweenService:Create

If you want to Tween a Singular Coordinate for Part Size:

TweenService:Create(YourPart,
 TweenInfo.new(1),
{Size = Vector3.new(YourPart.Size.X,25,YourPart.Size.Z)}):Play()

What this does is Keep the Original Coordinates for X and Z, but only changes the Y value

i guess you can group all parts in one model or union them

I’ve tried this script and it does move the part in the current position, but it makes the Y value 0.001. My script is down below


local function CreateResizeTween(instance, tweenInfo, normalId, deltaAmount)
	local delta = Vector3.FromNormalId(normalId) * deltaAmount
	return TweenService:Create(instance, tweenInfo, { Size = script.Parent.Size + delta, Position = script.Parent.Position + delta / 2 }):Play()
end

CreateResizeTween(script.Parent, TweenInfo.new(5), Enum.NormalId.Bottom, -5) 

I get that this works, but as stated in my original post, when you do try do something like this all it does is make the part size expand in both ways. I only want it to go down in one direction.

I’ve tried your code, and it seems to work for me.
https://gyazo.com/dd0326067f2d1718fb1d6d9f1f533c6c

Could you send a GIF of how it looks on your end?


but it makes the Y value 0.001

Is this for the instance's Size or Position?

It’s on the instances size, sure I will send a video if that works.

1 Like

Are there other scripts which change the size of the curtain as well?

You can find places where its Size is changed by pressing CTRL/CMD + Shift + F, then typing the variable name used to reference the part in the script (typing Size in the search bar would help).

Think this should be 5, in this case you would be subtracting from the bottom instead of adding. Since your part’s Y size is smaller than 5 it would result in it becoming a negative which would clamp at 0.001.

There are other scripts that use TweenService that changes sizes in the game, but I don’t really think it’s the cause. If so, I’ll open up a temporary baseplate and see.

Yes, I’ve changed that after I posted the script, it still goes 0.001.

Edit: Still the same result in the different baseplate, can you show me how you’ve done your script that could be different from mine? Also I forgot to mention, when I did -5, the part expands upwards which is the opposite direction of what I want.

Oh I see, maybe it’s because Vector3.fromNormalId(bottom) is in the -Y direction so you would probably have to separate delta size from position. So for each axis of the vector we can just use math.abs on it. However, we also have to handle the case where deltaAmount is less than 0 to resize negatively, we could do this by just multiplying the deltaSize by math.sign(deltaAmount)

So something like:

local function CreateResizeTween(instance, tweenInfo, normalId, deltaAmount)
    local deltaSize = Vector3.fromNormalId(normalId) * deltaAmount
    deltaSize = Vector3.new(math.abs(deltaSize.X), math.abs(deltaSize.Y), math.abs(deltaSize.Z)) * math.sign(deltaAmount) -- if deltaAmount is less than 0 it will reduce the size, else it will increase the size
    local deltaPosition = Vector3.fromNormalId(normalId) * deltaAmount
    return tweenService:Create(instance, tweenInfo, {Position = instance.Position + deltaPosition / 2; Size = instance.Size + deltaSize})
end
1 Like

Initially, I copied your code directly into a new script, but now I’ve fiddled with the numbers and managed to get something promising.

https://gyazo.com/dfa4f7fee9c98fd01228953a510be8eb


For the Position property, I changed + delta / 2 to - delta / 2

Position = script.Parent.Position - delta / 2

and I changed the last value for CreateResizeTween() from -5 to 5 (thanks @7z99 for this part).

CreateResizeTween(script.Parent, TweenInfo.new(5), Enum.NormalId.Top, 5)

if you are trying to do something like this then the below tween should work
what you do is set a part to the size and position you want your part to tween to then tween size and cframe to that part

local part1 = workspace.Part1
local part2 = workspace.Part2
local Tween = game.TweenService:Create(part1,TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out),{CFrame = part2.CFrame, Size = part2.Size})
Tween:Play()
1 Like

Hello, thank you so much, your code does indeed work but I’ve comprised your code with @GreatPanda3 code so it’s a bit more shorter.

For people who want the code to help with their problem:

local TweenService = game:GetService("TweenService")

function CreateResizeTween(instance, tweenInfo, normalId, deltaAmount)
	local delta = Vector3.fromNormalId(normalId) * deltaAmount
	delta = Vector3.new(math.abs(delta.X), math.abs(delta.Y), math.abs(delta.Z)) * math.sign(deltaAmount) -- if deltaAmount is less than 0 it will reduce the size, else it will increase the size
	TweenService:Create(instance, tweenInfo, {Position = instance.Position - delta / 2, Size = instance.Size + delta}):Play()
end

CreateResizeTween(script.Parent, TweenInfo.new(5), Enum.NormalId.Bottom, 8.5)

@Nyonic Hey, I can see that your code does work but that method is kind of what I wanted to avoid, individually setting the position and size for each part. But thanks for being kind enough to provide a solution.

Anyways, thanks for the help everybody. :sunglasses:

4 Likes

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