Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Trying to tween the CFrame of a model?

I'm working on my own custom placement system, and I thought it would be nice to have the model smoothly move between points with the mouse. I am struggling trying to figure out how to move the whole model. My current code is:

local TweenService = game:GetService("TweenService")
local TI = TweenInfo.new(0.05, Enum.EasingStyle.Quad)

local newTween = TweenService:Create(currentModel.PrimaryPart, TI, {CFrame = cf})
newTween:Play()

Please note, I did not show the full code here. CurrentModel is the model I am trying to move. cf is the Frame I am trying to move it to.

The problem is, this ONLY moves the primary part of the model. Can someone help?

1 comment

0

Maybe you coul add a motor6D / Weld to connect every part in the model with this plugin https://web.roblox.com/catalog/804263305/Constraint-Editor

2 answers

✓ Accepted answer

Try using TweenService:GetValue() in combination with a loop that calls the method SetPrimaryPartCFrame() with a lerped cframe instead!

local TweenService = game:GetService("TweenService")
local Time = time() --Gets the starting value of time.
local Total = 1 --How many seconds till completion
local Model = workspace.Model --Location of model
local Start = Model:GetPrimaryPartCFrame() --Starting cframe to lerp with.
local End = CFrame.new() --End cframe to lerp to.
while time() - Time <= Total do --Will keep looping until beyond timeframe
	local TI = TweenService:GetValue((time() - Time)/Total, Enum.EasingStyle.Quad, Enum.EasingDirection.In) --Gets the value for which to lerp the cframe with.
	local CFrame2 = Start:Lerp(End,TI) --Gets the CFrame between start and end
	Model:SetPrimaryPartCFrame(CFrame2) --Sets the model's CFrame.
	wait() --Makes sure the game doesn't crash.
end

2 comments

0

There has to be an easier way to do this, this seems overly complicated. This works for now, but I may seek a different solution in the future.

0

Honestly I feel like this is one of the easiest ways to do it, the stuff that involves welds and motor6ds tends to require more preparing and adding stuff you wont need later

Mhhhhh... i have done something like this some time ago and did not work too and that's stupid imo.

Anyways what you could do to fix it keep the primary part anchored and for other parts use Weld Constraints to weld them to the primary part, also make sure they are not anchored.

2 comments

0

aww the downvotes...

0

i know right ahaha          give me one more

This discussion is preserved as it was. New answers, comments, and votes are closed.