Introduction to Tweening Models

Yeah, so are we still stuck with using welds?

No? Please read what I wrote in my reply and the top of the thread again. The legacy method does not use welds and I mentioned that pivots can be used as drop-in replacements for the legacy problematic functions dealing with primary parts.

1 Like

Oh, my apologies. The legacy method can still be used with using the pivot functions, however, the downside still is with the CFrameValue. So as long as I do not interact with this value while itā€™s tweening, my model wouldnā€™t have any issues, right? And also, what about this?

Donā€™t you think welds are more of a performant option? Or am I missing something here?

Itā€™s a bit of an overstatement but itā€™s comparing introducing a proxy instance for a quick movement versus applying the tween directly. Welded parts behave as if theyā€™re anchored anyway but are constrained in relative space to the part theyā€™re attached. Both are effectively updating CFrames in their respective steps.

Iā€™ll update the thread with further information at a later date.

3 Likes

Do you tween the model on the server or the client? Because in the Server it does seem to throttle a bit. I wouldnā€™t use collisions on that specific model, but I was thinking of using it to collide with the golf ball on my game (which has its physics handled on the server).

Rule of thumb is to make the client responsible for the movement in most or all cases. The server will inherently be incapable of processing intermediates as fast as a client be it interpolation or physics. That being said, in the case of a physics-based golf ball thereā€™s two possible routes I might go: have the rotation of the related obstacle also physically-simulated or push everything to the client and employ server validation for the golf ball (position tracking and the like).

1 Like

Oh, I guess Iā€™ll try to physically simulate it then, because the other seems like it would give a noclip impression for some players. Thanks.

how can I make two or more model tween as the same time. For instance, Iā€™m using this method to make a helicopter for my cutscene. I used this and I made the whole helicopter move, but I want the tail rotor and the top rotor to spinning around at the same time too. I tried to spin it by using CFrame.Angles but it just spin the whole model.

This tutorialā€™s primary coverage is on simple models and serves as a baseline for what you may expect for when you tween models. It doesnā€™t cover any higher level use cases like tweening submodels while keeping them relative to their parent model.

In the case of a helicopter, what youā€™re likely going to want to do is weld all parts of the respective rotors to a core part and then tween the C0 or C1 of that core part to form a rotation. For example, the top rotor parts would be welded to a ā€œmotor partā€ with a weld to the main body and you can change the CFrame offsets of that weld to give it the spinning effect you desire.

3 Likes

That can make it look unrealistic tbh

2 Likes

Nice! The script works! how would you move the model? Not rotating though

Movement is the second code sample in ā€œTweening Your Modelā€ directly under the first one which covers rotation.

1 Like

Iā€™ve been having a problem with this approach, and one that Iā€™m not sure can be solved. Iā€™m trying to make my model (on the client) make several revolutions in its orientation, and unfortunately CFrame angles get moduloed so that theyā€™re under 360 degrees. This makes it seemingly impossible to use a CFrame tween to accomplish what I want.

Using Orientation by itself makes only the PrimaryPart move, so thatā€™s out of the question. So, I found what at first I thought was a good solution: Tweening the CFrameā€™s Position and the Orientation separately. Unfortunately, this causes the PrimaryPart to move without rotating, and oddly enough, the welded parts rotate at an ever-increasing rate, for reasons I canā€™t quite discern.

Any help would be appreciated. Iā€™m all out of ideas. If a demo file is needed I can make one, but itā€™d probably take me a while to get around to it, as I donā€™t want to share the entire place file (for obvious reasons).

EDIT: Ugh, judging by other posts I found it looks like Iā€™m going to have to use RenderStepped for this. I donā€™t get why this isnā€™t supported by tweening CFrames and instead something I have to write like this. Any other approaches that feel less hacky are appreciated.

So unfortunate that this isnā€™t builtin to the engine. Thank you for the tutorial and code.

Here is an example of rotating a door several times around a hinge using a tween and some recursion magic (comments added to the local script for clarity):

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local door = ReplicatedStorage:WaitForChild("Door"):Clone() --Door is a model with a few parts welded together
local hinge = door:WaitForChild("Hinge") --Hinge is the primary part of the model and is the only anchored part
door.Parent = game.Workspace
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween

local function RotateDoor()
	--This will grab the hinge's current pivot and rotate it by 120 degrees (use -120 to rotate in the other direction)
	--This does not go to a 120 degree fixed orientation in the workspace, rather it transforms the current rotation by 120 degrees
		--It works regardless of the current rotation
	--120 is chosen because it is a factor of 360, so the tween will always move in the same direction
	tween = TweenService:Create(hinge, tweenInfo, {CFrame = hinge:GetPivot() * CFrame.Angles(0,math.rad(120),0)})
	tween:Play()
	tween.Completed:Connect(RotateDoor)
end

local function DestroyTween()
	tween:Pause() --Immediately stops the tween in its current location. Using cancel or destroy has a small delay
	tween:Destroy() --Cleanup
end

RotateDoor() --Initial play to begin the loop
task.wait(8)
--An example of how to stop the tween loop
DestroyTween()

task.wait(3)
--And how to restart it after it was stopped
RotateDoor() --Notice how the object will resume its rotation from its current spot and doesn't need to reset

Hereā€™s a short vid to show it in action:

Be aware more logic is needed if the object returns to a default state.

Hope it works out for ya!

P.S. You could also create this using 3 different tweens with static rotational values, and would probably work out better if the object needed to return to a default state. It would probably also be more performant since youā€™ll only need to create the tweens once ā€¦suppose I shouldā€™ve coded it that way lol.

2 Likes

Hey! Im new to tweening models, however it wont let me add -0.2 to the Z coordinate of the tween, here is what iā€™ve got,

local TweenServ = game:GetService("TweenService")

local DoorLeftModel = script.Parent.Left
local DoorRightModel = script.Parent.Right

wait(3)
TweenServ:Create(DoorRightModel.PrimaryPart, TweenInfo.new(1), {CFrame = DoorRightModel.PrimaryPart.CFrame + CFrame.new(Vector3.new(0, 0, -0.2))}):Play()

And its saying vector 3 is expected.

I need some help. I donā€™t how I can tween a single model
ā€“ References ā€“

local TweenServ = game:GetService(ā€œTweenServiceā€) ā€“ CRTICAL - DO NOT TAMPER WITH ā€“

local TweenDoor = script.Parent:WaitForChild(ā€œDoorModelā€)

local TweenInform = TweenInfo.new(0.5)

ā€“Configurationā€“

Enum.EasingStyle.Linear,

Enum.EasingDirection.InOut,
this is my script here. can somebody help me please with this?

Iā€™m new to use tweening so i need a bit of help
I donā€™t know how to tween objects
I only know a few things about scripting

I do exactly this
I make a tween for the primary part where it simply goes up and down
Every single part doesnt move except for primary part
pain.

This will absolutely do nothing and throw out errors, arenā€™t you better off just copying the script he gave in the example? It works perfectly fine