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)
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
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
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.
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.
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.