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))))
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.
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.
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?