How do I use TweenService with :SetPrimaryPartCFrame()?

I need to set a models CFrame, I want it to tween, How do I accomplish this?

Please search for related topics first next time. You might find your answer here:

7 Likes

I used this solution to tween my projectiles.

Be careful with this solution, you’ll suffer from floating point precision errors.

1 Like

The only other parts in it are just particles, so the floating point errors don’t matter much.

1 Like

In order to get the Primary Part’s CFrame, You need to have a Part set to the PrimaryPart property in the Model’s properties.

RobloxStudioBeta_2017-12-04_16-33-10RobloxStudioBeta_2017-12-04_16-33-36

And here’s a code I found in a similar topic’s replies:

local tweenService = game:GetService("TweenService")
local info = TweenInfo.new()

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

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

Hope this helps, If it doesn’t… well I at least tried.
¯_(ツ)_/¯

7 Likes

Thanks all of you! I ended up using the CFrame Value method. It works well enough for what I’m using it for.

1 Like