Tween a model (move the model)

image
Im trying to tween a model but i got this error, how i can fix this?

1 Like

You cant tween the model directly, you should choose its primary part.
Plane.PrimaryPart, make sure your model has that property chosen.

Plus, its better to tween the CFrame and not the Position property, if you expect the model moves along with all the welded parts in it

1 Like

I had already selected the primarypart

Can you show me an example of what the script would look like?

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local tweenGoal = {CFrame = CFrame.new(-24.665, 194.851, -36.144)}
local TweenTrack = game.TweenService:Create(Plane.PrimaryPart, tweenInfo, tweenGoal)
TweenTrack:Play()
1 Like

I stumbled accross this issue where I “”“needed”" to Tween a Model. You can’t Tween a Model directly because of Roblox limitations. But you CAN Tween CFrameValue and each time the Value is updated during Tweening move the PrimaryPart using SetPivot (AKA SetPrimaryPart but not deprecated).

Here is an example in Luau that uses a function to do this approach.

local TweenService = game:GetService('TweenService')

function TweenModel(Model:Model, info:TweenInfo, CFrame:CFrame)
	-- Create a new CFrame Value and a tween for it
	local Value = Instance.new('CFrameValue')
	local tween = TweenService:Create(Value, info, {Value=CFrame})
	
	-- Set the value to the Model starting position or else it will be 0,0,0
	Value.Value = Model:GetPivot()

	-- Each time the value changes, move the Model
	Value.Changed:Connect(function(new)
		Model:PivotTo(new)
	end)
	
	-- Destroy the Value once the tween is complete, maybe destroy the Tween too ?
	tween.Completed:Connect(function()
		Value:Destroy()
		tween:Destroy()
	end)
	
	-- Return the Tween object so you can play it, listen to completion
	return tween
end

-- Play the animation and say 'Tween completed !' once it ends
local ModelTween = TweenModel(
	workspace.Model, TweenInfo.new(2), CFrame.new(10,0,0)
)
ModelTween:Play()
ModelTween.Completed:Connect(function() print('Tween completed !') end)

If the comments are overwhelming, you can remove them. All that matters is that you can understand the code so you can find your own solution to problems.

Also please keep in mind that this approach may be hungry for performance, especially with a large amount of parts in a Model! You should use Roblox physics or create a rig for it to animate with an AnimationController

2 Likes

Its exactly what I said, just… ok… You think primary part is deprecated? yeah, we can just use a custom root part inside the model exactly as characters does, isnt? or any way to get the root part of the model… your format sounds like a popular “AI” out there xDD
I support, Linux works good, we’re fine with Luau :3

PrimaryPart is not deprecated. I meant that using SetPivot method is performance hungry and that using an AnimationController and rigging the Model is the preferred way in some cases.

Also lol I probably sound like an AI but It’s really an human that wrote that, or a machine learning model ?

But anyways, yes Linux works good until a Roblox update breaks Grapejuice, that would be cool if more players and dev changes their displayname like that until Roblox is aware. Please Roblox, add Linux support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.