How do I tween in one direction?

Currently when my part tweens it scales in all directions, however, I just want it to scale on one axis.

How do I fix this?

My code:


Open = true

ClickDetector.MouseClick:Connect(function()
	if Open == true then
		local tweenService = game:GetService("TweenService")
		local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0)
		local part = script.Parent.Parent.Parent.Shutter
		local goal = {Size = Vector3.new(12.872, 0.511, 0.05)} -- New size.
		local tween = tweenService:Create(part, tweenInfo, goal)

		Open = false

		tween:Play()
		
	elseif Open == false then
		local tweenService = game:GetService("TweenService")
		local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0)
		local part = script.Parent.Parent.Parent.Shutter
		local goal = {Size = Vector3.new(12.872, 0.511, 0.05)} -- New size.
		local tween = tweenService:Create(part, tweenInfo, goal)
		
		Open = true
		
		tween:Play()
	end
end)
2 Likes

Hi! Are you wanting it to scale in one direction like this?

https://gyazo.com/9afffa9797e061faaaf74a1f9557d713

or is it gonna scale in multiple directions, but you want one side to stay in the same place?

1 Like

Yeah! One direction, it’s for my shutters.

Alright, I just made something that used similar scripting. Assuming that the current problem is that the part is scaling in both directions, you can include something like this,

Position = Vector3.new()

If you are scaling the part on the x axis for example, keep the y and z position the same, you can change the x axis so the part will move with the scale.

If this isn’t what you wanted, or you want me to explain it differently just let me know.

(This is what I did to solve a similar problem)

Here is an example,

https://gyazo.com/257ae5c4065f7ea8ba309b92b4a75b36

Where would I put that? Also thank you for helping!

local goal = {Size = Vector3.new(6.75, 6.75, 1.25); Position = Vector3.new(-23.625, 3.375, -78.75)}

of course your numbers would go in for the Vector3.new values.

1 Like

https://gyazo.com/b8eee1861cbcbe873f5f5c64324350ca

This is what happens.

The thing is:

--// Services
local TweenService = game:GetService("TweenService");

--// Settings
local ANIMATION_TIME = 2; --> Tween animation period.
local Y_INCREMENT = 0;
local X_INCREMENT = 5;
local Z_INCREMENT = 0;

--// Dependencies
local Part = script.Parent.Parent;
local ClickDetector = script.Parent;

--// Functions
ClickDetector.MouseClick:Connect(function()
    local TweenInfo = TweenInfo.new(ANIMATION_TIME , Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, 0, false, 0)
    
    local Goal = {
        Size = Part.Size + Vector3.new(X_INCREMENT, Y_INCREMENT, Z_INCREMENT),
        CFrame = Part.CFrame * CFrame.new(X_INCREMENTO / 2, 0, 0)
    }
    
    local myTween = TweenService:Create(Part, TweenInfo, Goal);
    myTween:Play()
end)
5 Likes

Negative number = Inverse side.

1 Like

Didn’t even think about doing it that, way, this way is a lot better, and easier to change.

1 Like

Thank you! This worked :slight_smile: .