TweenService For Models

As we all know, the TweenService is a very powerful tool. It’s useful for moving parts on the server level because the server very rarely has a perfect 60 FPS, but Tweens on the server still remain smooth.

It would be very useful if this functionality extended to models instead of just single parts. The ability to move an entire model using a single tween would be awesome.

Yes, I could use a for loop, PivotTo(), and TweenService:GetValue() to accomplish a similar effect, but it can only be as smooth as the server is and very frequently leads to choppiness. Also just creating a tween for every part in the model is a horrible technique and usually breaks joints between assemblies.

13 Likes

is it a wait() loop or a RunService heartbeat loop
honestly I hate the way TweenService is restricted to just instance properties and would be much more useful if it supported functions

2 Likes

Even using heartbeat it’s still tied to the choppy un-smooth server refresh rate.

I never knew about that
anyway to work around this limitation i think you can create a CFrameValue and connect the Changed event to move the model, then tween the CFrameValue

1 Like

I don’t think I’ve had an issue with moving objects with tweening CFrameValues and using :GetPropertyChangedSignal().

Are you moving these models on the server or the client? Games tend to only update movement on the client for the issue you are describing with the server refresh rate by compensating using interpolation.

tweeningmodels.rbxl (1.0 MB)

1 Like

When adding animations into my game I always come across this issue. I am mostly tweening model like doors, cutting down trees, spinning objects, etc.

Basically, I prefer to use tweens rather than relying on unanchored parts with a Constraint inside. I animate models really often and un-anchoring them to insert a constraint and weld everything together is a big NO NO for me.


:red_circle: To tween models I do:

  • I currently need to create a ValueBase with CFrame or Vector3 for position, I tween it and as it changes I update the model using PivotTo.
  • I currently need to create a NumberValue for size (scale), I tween it and as it changes I update the model using ScaleTo.

:green_circle: I would love Roblox to add five new functionalities like the GuiObjects have called:

  • Model:TweenCFrame() → cframe
  • Model:TweenPosition() → position
  • Model:TweenSize() → scale
  • Model:TweenPositionAndSize() → position & scale
  • Model:TweenCFrameAndSize() → cframe & scale

Add some way to loop them as well though, or maybe expose tween able properties to fix this issue.


If you think that’s a lot, then wrap it all under one API, but I need these functionalities to tween models around.

1 Like

Can’t you make your model to have 1 anchored part, weld every other part to that anchored part and tween the anchored part? Idk if I am missing something here, but I tested it and it works perfectly for me

Otherwise, if you want to get a smooth result when making your own tween with a loop, you need to calculate the completion % using tick() (or other functions), basically something like this

local TWEEN_TIME = 10

RunService.Heartbeat:Connect(function() 
	local ModifiedTick = tick()/TWEEN_TIME -- Takes 10 seconds to go up by 1
	local alpha = ModifiedTick - math.floor(ModifiedTick) -- becomes a value that goes from 0 to 1
	
	local ResultCFrame = CFrame1:Lerp(CFrame2,alpha)
end)

You can also use the deltaTime value returned by RunService.Heartbeat to increment a value instead of using tick()

The point is clearly more - why do developers need to go to this effort when there should really be an API in place?

I agree with the feature request - I would love for native model tween support without all the various workarounds (welding all parts to a root or pivoting) - but I’m not sure what the server has to do with anything here, since TweenService runs on PostSimulation frequency (or it might’ve been Pre, a Release Note mentioned this before). You get the same effect whether it’s from TweenService or a custom solution.

2 Likes

In my opinion, it’s not that much effot to tween 1 part in the model (well I do make tiny scripts to weld all the parts togheter). From testing, I have also found that using PivotTo() on a model is slower than using PivotTo() (or changing the CFrame manually) on an 1 anchored part in a model with everything welded to it, so a native solution would probably end up being slower than this solution. It would be more convenient, I get that.

The bigger problem to me is how this solution doesn’t seem to be known by most developers?
Roblox’s ressources would be better spent elsewhere in my opinion.

You are only focusing on animating a model’s position, which of course, is what this topic also focuses on.

But it would also be amazing to tween scale :smiley: !


:red_circle: Position/CFrame:

The alternative method of tweening position you are talking about it is indeed good and you could say “simple” enough when you have a wrapper that already does it for you.

But imagine welding every model you will be animating in your game. If you have 400 models containing 10 parts inside, you will need around 4000 extra WeldConstraint to be able to animate them by tweening the PrimaryPart.

This is why I prefer the method of PivotTo instead as it should use less resources. (This is my opinion though)


:green_circle: Scale:
Back then developers had to do some math to get the right position and size on all parts under a model, to then tween them all to that goal.

With the new method Roblox added called ScaleTo is 10x easier to do now and is kind of like the PivotTo method of animating.


Since they are done too often in the engine, I imagine the engine should offer some APIs in order to achieve these tasks faster. My game has a lot of models that I tween, I barely go and tween parts individually in my game, which means is a big issue for some other games.

If is just three models in your game, then it won’t matter as much but I do it to so many models and even to create effects.


I would love to just go and do TweenSize and TweenPosition on the model without needing to go through this task.

Roblox is releasing so many features that I think they are completely useless and unnecessary. Yet it’s fine since they are improving the engine for everyone, and those features that I believe to be currently useless, I can find them useful one day. (Just like this one) :wink:

1 Like

For scale, it would be great is TweenService could access the scale property (which is not scriptable)
image

Updating CFrames is kind of expensive when you update a lot of parts every frame, maybe some kind of engine limitation is preventing scale from being scriptable, idk.

Do you mean less ressources performance wise or work wise. Performance wise, PivotTo() is slower

1 Like

And should make PivotTo() function not laggy. I have already made custom functions for tweening models cframe and size, but due to this trash :PivotTo() function being unoptimized it lags a ton, I gotta do this weld BS all the time.

1 Like

In terms of performance like you mentioned it is indeed slower than just updating a Part’s CFrame, but I prefer to use this function even though is slower because I would save myself having 4k WeldConstraints which would be required in the example I gave you of 400 models containing 10 parts each. Unless PivotTo does something worse than this, which I doubt it (though they mention the offset of descendants is cached and idk to what extent).

The method of welding brings issues like:

  • Welding the whole model.
  • You need to un-anchor BaseParts and keep the main one anchored; and creates some organizations issues where all the parts of the model should be anchored.
  • GetChildren/GetDescendant calls can slow down a bit on large models.
  • Should occupy more memory as you are having more instances to hold things in place for the solely purpose of animating a model.

Welding and destroying welds after usage wouldn’t be so efficient if the model will be animated often, so you are forced to keep them in place.

This is my opinion on it, thank you.

Fair point. In my case, I only have a chairlift thing that basically moves the chairs around. I move the entire chair and don’t have to worry about only animating a portion of the model or stopping the animation and stuff.

1 Like