TweenService: How does that work?

Hello!

I have a model called “MyModel” that I needed to move around the map without TPing it.
I first tried :SetPrimaryPartCFrame, but sadly, the model was lagging when doing that, so I got that idea out of the way.

I looked up a bit for alternatives, and ended up finding “TweeningService”.
I tried to reproduce examples, but it wouldn’t work. It moved my model, but it also outputted “Argument 3 Missing or Nil”.

Here’s the code I wrote:

wait(5)
local TS = game:GetService("TweenService")
TS:Create(game.Workspace.Model, TweenInfo.new(5), game.Workspace.Model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 25, 0))))

What’s wrong with this code?

Thanks in advance!

In order to tween the positions of Models using TweenService, one must use TweenService to tween a CFrameValue and use a CFrameValue.Changed:Connect(function()) to call Model:SetPrimaryPartCFrame() on the given model. As CFrame is not a settable property of models, this workaround has to be used.

Because of this odd quirk, whenever you are intending to move a model it’s worth considering whether it is possible to weld all parts of the model to one center part and have it behave as a physics assembly. That will give you one part which you are able to CFrame directly using TweenService, with the other parts following along.

To be more specific on “What’s wrong with this code?”, the third argument of TweenService:Create() is a table of properties and their desired values. You cannot supply a method as it will not be executed. If CFrame was a valid property of the Model, the third argument could be
{CFrame = CFrame.new()}

You might also want to call :Play() on your newly-created Tween so that it will play correctly. Currently you are defining the tween but never playing it.

2 Likes

Okay, going to try that. I’ll keep you updated.

2 Likes

I wrote a tutorial on how to tween models.

Don’t use SetPrimaryPartCFrame, seriously. It’s an awful function what with its floating point imprecisions. I address this around the bottom of my thread.

3 Likes

if you just want to move it around the map you can use BodyPosition and BodyGyro

Tried to use some exemples on your tutorial and edited them to fit my requirements, and, after correcting some errors, the model is going slightly up. How to fix this?

Mind explaining what you mean or providing a repro regarding this behaviour (code, video and/or barebones place file reproducing the issue)?

  1. Sorry for not answering earlier, thought I had answered this yesterday.
  2. The issue that what I wrote is:
[code].CFrame = script.Parent.CFrame * CFrame.new(150, 5, 150) 

but should have wrote

[code].CFrame = CFrame.new(150, 5, 150)

It works perfectly and smoothly, thanks you alot!