Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with using Tween Service on Models?

I've recently tried to tween a model by its PrimaryPart but It only tweens the PrimaryPart and not the entire model. I've even tried welding every part in my model to it's PrimaryPart and it still doesn't give me the result I'm looking for.

The code I use to tween is below. Any suggestions or changes I should make?

local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(
	5,
	Enum.EasingStyle.Elastic,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local Pos = {}
	Pos.Position = Vector3.new(Character.UpperTorso.CFrame*CFrame.new(0, -1.7, -4));

local tween = TweenService:Create(MyModel.PrimaryPart,Info,Pos)
tween:Play()

1 answer

✓ Accepted answer

You are not able to tween a model as it has no position value. The position is based upon the primary part which you need to use the function SetPrimaryPartCFrame.

You can however use the lerp function of a CFrame but this will not have the same easing style.

Example:-

local endCF = Character.UpperTorso.CFrame*CFrame.new(0, -1.7, -4)
local startCF = MyModel:GetPrimaryPartCFrame()

for i=0, 1, 0.1 do
	MyModel:SetPrimaryPartCFrame(startCF:lerp(endCF, i))
	wait()
end

I hope this helps.

2 comments

0

Thanks! This worked perfectly.

0

Make sure you accept it as an answer if it worked for you... It helps the poster's reputation and makes sure the community knows they can answer questions helpfully.

This discussion is preserved as it was. New answers, comments, and votes are closed.