How do I make it so it tweens to the side?

So I am currently making a script that tweens the size of a part.
But I want it to tween the size like this.

Before tween:

After tween:


How do I do this?

Source from Snapchat MyAI

local TweenService = game:GetService("TweenService")
local part = -- the part you want to tween
local targetRotation = -- the target rotation you want to tween to
local targetPosition = -- the target position you want to tween to

local tweenInfo = TweenInfo.new(
    -- duration of the tween in seconds
    1,
    -- easing style of the tween
    Enum.EasingStyle.QuadOut,
    -- easing direction of the tween
    Enum.EasingDirection.Out,
    -- number of times to repeat the tween
    0,
    -- whether or not to reverse the tween
    false,
    -- delay before the tween starts in seconds
    0
)

local rotationTween = TweenService:Create(
    part,
    tweenInfo,
    {Rotation = targetRotation}
)

local positionTween = TweenService:Create(
    part,
    tweenInfo,
    {Position = targetPosition}
)

rotationTween:Play()
positionTween:Play()

In this example, we’re getting the TweenService object and the part we want to tween. We’re also defining the target rotation and position we want to tween to. We then create a new TweenInfo object that defines the duration, easing style, easing direction, number of repeats, and delay for the tween. We use this TweenInfo object to create two new tweens, one for the part’s rotation and one for its position. Finally, we play both tweens using the Play function.

local TweenService = game:GetService("TweenService")

local part = -- insert your part here
local targetRotation = -- insert your target rotation here
local targetPosition = -- insert your target position here
local duration = -- insert your duration here

TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.QuadOut, Enum.EasingDirection.Out), {Rotation = targetRotation, Position = targetPosition}):Play()

In this example, we remove the function and create the tween directly using the Create and Play functions of the TweenService, along with the TweenInfo and properties table. This code is even more concise, but it may be less readable and harder to modify than the previous examples.

1 Like

Why do I rotate the part in the tween? Im not trying to rotate it so I am confused.

My bad you could probably just tween the cframe

Um, how would I do that?
Cause like I have tried some stuff but cant figure it out.
If you need some of the code I have now tell me!

Are you trying to make it swing like a door

1 Like

basically I need to make it kinda like an elevator door.

When the door opens it it slides to the right(Or left).
But I just want to change the size and make it smaller.
so like in the pictures.

Ohh sorry i thought it rotated I’ll just check you can probably just twwen the size depending on direction

If I was to just tween the size it will go like this

before tween:

After tween:


I need to make it so it tweens more like this:
Before:

After:

local TweenService = game:GetService("TweenService")

local part = -- insert your part here
local targetPosition = -- insert your target position here
local targetSize = -- insert your target size here
local duration = -- insert your duration here

part.Anchored = true
part.CFrame = CFrame.new(targetPosition)
TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.QuadOut, Enum.EasingDirection.Out), {Size = targetSize}):Play()

This code anchors the part to prevent it from falling or moving during the tween, sets its initial CFrame to the target position, and creates and plays a Tween that targets the Size property of the part. You can adjust the targetPosition, targetSize, and duration values to achieve the desired position and size change effect. Keep in mind that the Size property is a Vector3 value, so you need to provide three numbers to represent the target size.

This also wont work. I need it to like look like it is sliding.
If I do this the CFrame will just move instantly.
Which is not what I want.

Try using position and Vector3 instead.
CFrame is a bit hard for beginners.

Ok I can see what you are saying.
But I have to use CFrame because its using welds and other wise it goofs with it.

also.
I am not a noob lol, I am actually working on a pratty big project, so lol(Ik its not that deep I just had to clarify lol)

1 Like

This requires both the tweening of size and position properties

from the after image, copy the position down and put it into the script as a goal for position, undo

add in the size goal

play tween.

of course, you’ll want to make it more universal by utilizing the part’s .position and subtracting or adding to the position in reference to position final and position initial, that way it will work wherever you place the part.

now you can utilize the cframe, it just requires you to do the same thing as you done for the position, however you have to utilize it inside cframe.new()

2 Likes

sorry my phone died i made this rq it can be cleaned up but it works


local part = script.Parent
local Original_Position = part.Position
local Original_Size = part.Size
part.Anchored = true

part.Touched:Connect(function(player)
	if player.Parent:FindFirstChild("HumanoidRootPart") then
		local targetPosition = Vector3.new(47, 5, -15)
local targetSize = Vector3.new(2, 10, 2)
local duration = 2

	
	TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = targetPosition}):Play()
    TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = targetSize}):Play()
	wait(4)	
	TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = Original_Position}):Play()
	TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = Original_Size}):Play()	
	end	
	end)
1 Like

Try this,

{[CFrame] = CFrame.new(Vector3.new(your value))}

Isnt this going to just move it to a vector3 position?

1 Like

I’ve made a little degenerate drawing in paint to see how i can do this


Maybe this will help, i will explain :
so what we want is to change the size but keep the start of the part at the same point.
To achieve that we need to change the position of the part when we change the size, which is represented by m in the picture above ( the middle ) in the first line AB m’s x coordinate is 3.5.
After we reduce the size by 4 in the line above, m’s x coordinate becomes 1.5, that’s because when reducing the size by 4 we take out 2 from each side so the center needs to move by 2, and 3.5-2 = 1.5, hence the m position in the smaller line.
With that we can conclude the following equation:

NewPos = PrevPos - (PrevSize - NewSize)/2
--or
NewPos = PrevPos + (PrevSize - NewSize)/2
-- depending on the rotation i'm not sure which one

In conclusion you can tween the size alongside the position to achieve the final desired look. The only problem is i don’t know if it will be smooth enough.
Hope that helped :grin:

1 Like

I had a bit more time

local TweenService = game:GetService("TweenService")
local part = script.Parent
local Original_Position = part.Position 
local Original_Size = part.Size 

local scale = Original_Size.X / 1.05 -- Alter this to change the Thickness of the Door afetr the tween 
local duration = 2
local delay = 3

local targetSize =  Original_Size  - Vector3.new(scale, 0, 0) 
local targetPosition = Original_Position  + Vector3.new(scale/2, 0, 0) 

local Open = TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Position = targetPosition,Size = targetSize})
local Close = TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Position = Original_Position,Size = Original_Size})


part.Touched:Connect(function(player)
	if player.Parent:FindFirstChild("HumanoidRootPart") then
		Open:Play()
		wait(duration+delay)	
		Close:Play()

	end	
end)