How do I move a model with Tween Service?

I tried using a primary part but it won’t work. Please help! I just want to change the positing of the model. Also I’m new to TweenService so some complicated code might be unreadable for me.

1 Like

One way is to use a CFrameValue which when change updates the CFrame of the model

local Model = 
local Goal = CFrame.new()
local Info = TweenInfo.new(1)

local CF_value = Instance.new("CFrameValue")
CF_value.Changed:Connect(function(V)
	Model:PivotTo(V)
end)
CF_value.Value = Model:GetPivot()

local Tween = game:GetService("TweenService"):Create(CF_value, Info, {Value = Goal})
Tween:Play()

Pivot: GetPivot, PivotTo

That code is a little bit unreadable for me, but please tell me where do I put the primary part’s destination or goal?

Goal is the CFrame where the model should move and Model is the model, example:

local Model = workspace.TargetModel
local Goal = workspace.Goal.CFrame

Tweening models has always been a bit of a headache, but I recommend you follow this tutorial, it helped me tons before.

In a nutshell, you weld everything to the PrimaryPart (which is anchored) and tween that.

1 Like

I recommend making a model with 2 parts welded together, set the primary part by accessing the properties tab of the model and going into the pivot section like below.
image

Then create a simple tween script that adjusts the position of the primary part, and the other part should trail along. Apply this to the model you are currently using, and it should work.

(Note: I use moon animator to apply welds to my parts. It’s what worked for me, so if you aren’t getting the desired effect, I recommend getting the plugin)

Also like what @Inconcludable said, make sure your primary part is anchored.

Well, sorry it didn’t do anything. Here is the script I have.

local tweenService = game:GetService("TweenService")
local door = script.Parent.Parent.LeftWall
local close = CFrame.new(-3.5, 5.75, 310.75)

local info = TweenInfo.new(
	0.6,							--Length (Seconds)
	Enum.EasingStyle.Quad,		--Easing Style
	Enum.EasingDirection.Out,	--Easing Direction
	0,							--Times repeated
	false,						--Reverse
	0							--Delay (Seconds)
)

local CF_value = Instance.new("CFrameValue")
CF_value.Changed:Connect(function(V)
	door:PivotTo(V)
end)
CF_value.Value = door:GetPivot()

local closeDoorTween = tweenService:Create(CF_value, info, {Value = close})

script.parent.ClickDetector.MouseClick:Connect(function()
	print("clicked")
	closeDoorTween:Play()
end)

I tried that tutorial, it’s too overly complicated for me, and I plan to do much more with this so it seems very inefficient.

Strangely it doesn’t work when CF_value.Value = door:GetPivot() is up, although it should work

local tweenService = game:GetService("TweenService")
local door = script.Parent.Parent.LeftWall
local close = CFrame.new(-3.5, 5.75, 310.75)

local info = TweenInfo.new(
	0.6,						--Length (Seconds)
	Enum.EasingStyle.Quad,		--Easing Style
	Enum.EasingDirection.Out,	--Easing Direction
	0,							--Times repeated
	false,						--Reverse
	0							--Delay (Seconds)
)

local CF_value = Instance.new("CFrameValue")
CF_value.Changed:Connect(function(V)
	door:PivotTo(V)
end)

local closeDoorTween = tweenService:Create(CF_value, info, {Value = close})
script.parent.ClickDetector.MouseClick:Connect(function()
	print("clicked")
	CF_value.Value = door:GetPivot()
	closeDoorTween:Play()
end)
1 Like

I am an intermediate scripter but after playing around with parts, I found that if you union all of the parts, then they all turn into one, and you can tween that.

It seems to work perfectly for me, but I am not an advanced scripter so I don’t know if there are any flaws to this.