How do I move the Model using TweenService?

I need to move the Model using TweenService, but when I specify the place where I need to move the Model using CFrame, I get an error, I understand that this is because the Model does not have a CFrame, but when I use Position, I also get an error. What can I use then?

2 Likes

Give the model a primary part and use :PivotTo() to move it

you generally do not want to be Tweening in the first place, but if you had no other options, you could instead use a Weld for all the parts to the RootPart, and move the RootPart through tweens. if you have any other questions, I gotchu.

also, he’s asking to smoothly move it, not to teleport the model. otherwise this would work out great

I was thinking about this option, but I need the whole model to have an Anchor.

Models don’t have a “Position” property. Closest thing they have is an “Origin” property, but that isn’t able to be edited by scripts.

You’ll either have to weld every descendant part to the Model’s PrimaryPart, or tween a CFrameValue and connect a function to its property changed signal, which then sets the pivot to the CFrameValue.

Ah whoops! You are correct :saluting_face: , But i think your approach would work best honestly. Or if you wanna get hacky you can just loop through each child of the model and tween it with a task.spawn function or something lol

1 Like

My tweening module, Tween+, actually allows for this.

You can’t tween directly the Models with TweenService, but theres a basic trick for that:

  1. Create a new Part instance and name it “PrimaryPart” for better understanding, anchor it, make it transparent, disable collisions of it, set the size to 0 (0.001, 0.001, 0.001), set the position of the part to the models, then insert it in the model.

  2. Set the PrimaryPart of the Model to the part you created which we have named “PrimaryPart”.

  3. Unanchor everything inside your model except the PrimaryPart, then weld them all to the PrimaryPart (preferably with WeldConstraints).

  4. Finnaly tween your PrimaryPart, the Model and the parts should follow your PrimaryPart.

Result:


(Red part is the PrimaryPart)

could you please tell me why you need to do this? you could just do what @McGamerNick suggested

Having multiple tweens play out just to move one model seems pointless, let alone how unperformant that sounds. I wouldn’t do this.

1 Like

The OP doesn’t want to create another model for some reason, its the only last hacky fix. A bunch of tycoons do this because its simply easier and task.spawn is light weight and handles everything. On the con side having a large model such as a map you should not tween it at all, example if a building is falling or whatever you should not tween i think it is possible to animate models? I haven’t dipped into that field but i believe it is possible so maybe playing the animation on the model would work better than tweening and when the animation is complete use pivot to to verify the model is in correct position.

I wouldn’t say that there needs to be a “last resort.” I mentioned above using a CFrameValue object and Pivot APIs to tween a model, which is a really common method, and works really well.

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
    2, -- Time
    Enum.EasingStyle.Cubic, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    0, -- RepeatAmount
    false, -- Reverses
    0 -- DelayTime
)

local function tweenModel(model, CF)
	local CFrameValue = Instance.new("CFrameValue")
	CFrameValue.Value = model:GetPivot()

    CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
        model:PivotTo(CFrameValue.Value)
    end)
	
	local tween = tweenService:Create(CFrameValue, tweenInfo, {Value = CF})
	tween:Play()
	
	tween.Completed:Connect(function()
		CFrameValue:Destroy()
	end)
end
3 Likes

There is an official ROBLOX tutorial on how to tween models. In their tutorial, they weld everything with WeldConstraints to the primary part and tween the primary part.

1 Like