(Solved) How to Tween a Model's CFrame with :SetPrimaryPartCFrame()

I’m making a door that opens and closes when you click it. Since the door is a model, I have to use CFrame (more specifically :SetPrimaryPartCFrame()) to move it. I’m not sure how to make the transition smooth using TweenService, though. Does anyone know how to do that?

local tweenService = game:GetService("TweenService")

local doorModel = script.Parent.Door
local doorModelPrimary = doorModel.Primary

local openPosition = script.Parent.OpenPosition
local closedPosition = script.Parent.ClosedPosition

local click = doorModel.ClickPart.ClickDetector

click.MouseClick:Connect(function()
	if doorModelPrimary.CFrame == closedPosition.CFrame then
		doorModel:SetPrimaryPartCFrame(openPosition.CFrame)
	else
		doorModel:SetPrimaryPartCFrame(closedPosition.CFrame)
	end
end)

I see you are trying to tween a model, have you read this guide on how to do it?
Introduction to Tweening Models - Resources / Community Tutorials - DevForum | Roblox

It was very helpful to me when I was starting out, I believe it can help you as well. If you have any questions about it, just ask here and I’ll try to answer.
edit: grammar

2 Likes

Make a CFrame value and set it to the door’s cframe

Tween the cframe value to the desired cframe but, before that, add a getpropertychangedsignal: value for the cframe and update the doors primary part cframe everytime that event fires

If you didnt understand ill send an example script

If you didn’t understand here’s a better explanation:

-Make a cframe value, and then use getpivot to get the doors primary paet cframe and set it to the value

-Listen to changes in the value and setpivot everytime it changes

-finally use tweenservice to tween the cframe’s value

Avoid using :SetPrimaryPartCFrame for animating a movement, overtime it presents rounding errors which creates gaps / cracks in your model. Instead weld the door together to one root part, and tween the root part’s CFrame. All welded parts as long as they are unanchored will follow the root.

nope, that was fixed some time ago, you can use both methods now

you should still use PivotTo. It’s better and newer. Roblox has plans to deprecate SetPrimaryPartCFrame so you should use PivotTo instead for new work.

1 Like

i mean i use pivotto as well, thought they already knew it was deprecated

https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame

Not deprecated just yet, just superseded.

2 Likes

Except I faced the exact issue of rounding errors creating gaps yesterday… So seems like it’s still an issue.

But with the PivotTo() I was unaware it was added, I haven’t touched Roblox for many months and this went right over my head. So I will try this out. And thank you for bringing this up I was looking for a fix to this in a project without needing to use physic constraints.

1 Like