Errors with Tweening Model Script

Hello,
I’m a relatively new scripter and have been trying to figure out how to tween a model
I found a script to use for moving a model, however it has some issues because this script is rotating the model for some reason and was wondering how might I fix this
I also tried to replace the part with door:GetPivot().Position + Vector3.new(0,0,0)) with door:GetPivot()*CFrame.Angles(0,math.rad(90),0) and got an error
Any idea why these things are happening, how to fix them, and if there are any better alternatives to moving a model?
I also want to make it open like a door but can’t figure out how to do that

local door = workspace:WaitForChild("DoorModel")
local ts = game:GetService("TweenService")
local cfv = Instance.new("CFrameValue")
cfv.Value= door:GetPivot()
cfv.Parent=script.Parent

local tween = ts:Create(cfv,TweenInfo.new(3,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0),{Value = CFrame.new(door:GetPivot().Position + Vector3.new(0,0,0))})
tween:Play()
cfv.Changed:Connect(function(value)
	door:PivotTo(value)
end)

This is not a very efficient way to tween a model. It requires an additional value, a CFrameValue, which is functionally deprecated and not optimal for most new game architectures.

Instead, I would recommend welding the model, keeping the PrimaryPart unanchored, and just tweening the CFrame of the PrimaryPart. All of the parts will stay together, and the pivot will be focused on the PrimaryPart.

However, if you do want to keep this method, the issue is that Instance.Changed will not fire when a CFrame changes if I recall correctly, in addition to .Changed only sending the property name instead of the property value (however this might be different for ValueBases, I haven’t checked). Instead, you’d have to use RunService.Stepped or any other callback that fires every frame.

Edit: I think I was wrong. The PrimaryPart should be anchored if it is the root part.

1 Like

I’ll have to try this later but it sounds about right
I tried this method but I had the primary part anchored which is probably why it didn’t work

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