Tweening a model/group

Hey, uhhh… it there any possible way to tweening a model, or we still need use a PrimaryPart and then costraint all the parts?

You could use a somewhat janky workaround I suppose

local model = -- your model here
local tweenInfo = TweenInfo.new()
local targetCFrame = CFrame.new(0, 10, 0)

local tweenValue = Instance.new("CFrameValue")
tweenValue:GetPropertyChangedSignal("Value"):Connect(function()
	model:PivotTo(tweenValue.Value)
end)
local tween = game:GetService("TweenService"):Create(tweenValue, tweenInfo, {Value = targetCFrame})
tween:Play()
2 Likes

Is there any other way, for me it’s not eficient to do that

I’m not entirely sure why it’s not efficient in your case to do it this way? Constraints or no constraints you’re moving an entire model and all of it’s parts along with it.

Afaik this is the only way to tween models outside of letting constraints do it for you.

Ok thank you for your answer. Any other answer everyone?

If performance issues arise because your model is quite large, I suppose you could use workspace:BulkMoveTo, but other than that, no.

It still not work… <><>scxszad

What do you mean by “not working”? that model:PivotTo(CFrame) is not working?
What is the model you wanna move, details? number of parts?

At least show the code you are using. Cause I dont see why the code Kizylle supplied would not work…

there isn’t really any other way of doing it. You could get the offset of each part and tween every part with the offset but then its just more efficient to do the cframevalue way.
try using this function, it works for me

function tweenModel(tweenInfo:TweenInfo,targetCFrame:CFrame,model:Model,usePivot:boolean?)
	local tweenvalue=Instance.new("CFrameValue")
	tweenvalue.Value=usePivot and model:GetPivot() or model:GetPrimaryPartCFrame()
	local tween=game:GetService("TweenService"):Create(tweenvalue,tweenInfo,{Value=targetCFrame})
	local update=tweenvalue.Changed:Connect(function(newValue)
		if usePivot then
			model:PivotTo(newValue)
		else
			model:SetPrimaryPartCFrame(newValue)
		end
	end)
	tween:Play()
	tween.Completed:Once(function()
		tween=nil
		tweenvalue=nil
		update:Disconnect()
	end)
end

just noticed this is sloved lol sorry

1 Like

Looks like it doesnt… idk at this point.

Btw, I like how you did show the same approach and not leaving loose ends, disconnecting and handling stuff existance.
But, if the first code didnt fixed it for @bagussetya11 I dont think a more structured code would solve it, I think could be on OP’s end

robloxapp-20230523-1603428.wmv (3,3 MB)

Context??? :+1:
The model is an elevator platform? the NPC?

The elevator suddenly start the tween from 0, 0, 0 coordinate. Yeah it’s an elevator.

did you set the start value for the CFrameValue?

local value=Instance.new("CFrameValue") --tweening this will make it start from 0,0,0
value.Value=model:GetPrimaryPartCFrame() --now it will start from the models primary part cframe

I’m not using your script. I’m using the @Kizylle one.

you’d still need to set the cframe value’s value, otherwise it will start from 0,0,0 since thats the default value of the cframe value and you’re setting the models cframe based on what the cframe of the value is

1 Like

Its the same… if you dont set the starting CFrame to Model pivot, how would the CFrame value would have the original Model pivot?

1 Like

Thank you so much! Thank you so much!

You too… thank you so much! Thank you so much!

1 Like

I don’t think my original post has loose ends. The CFrame value was never parented and the (active) tween was the only leftover process that could reference the CFrame value. No tween means no more reference to the CFrame value which means it gets GC’d which then itself disconnects all related events.

Either way though it’s better etiquette to clean up your stuff, just in case.

1 Like