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

How to move a model using TweenService?

Hello, how do i make a part move to a location using tweenservice? I tried to use Cframe but it is not smooth and i have seen a tutorial but its only for parts.

1 answer

✓ Accepted answer

If you want to move a model with TweenService, you can create a dummy CFrameValue, tween its value, and call SetPrimaryPartCFrame() on the model in the Changed event of the value.

Example:

local cfv = Instance.new("CFrameValue", model)
cfv.Value = model.PrimaryPart.CFrame

local function Tween(obj, t, properties) --my tween function, feel free to change it
	local TweenService = game:GetService("TweenService")
	local ti = TweenInfo.new(t, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	local tween = TweenService:Create(obj,ti,properties)
	tween:Play()
	return tween
end

cfv.Changed:Connect(function(val)
	model:SetPrimaryPartCFrame(val) --change the cframe of the model each time the CFrameValue changes
end)

Tween(cfv, 3, CFrame.new(20,0,0)) --change with your desired time and position

4 comments

0

Instance.new("class",parent) is deprecated. use local obj = Instance.new("class") obj.Parent = parent

0

Idc, it's deprecated because it's slow when creating objects updated by the physics engine. CFrameValue isn't one of them, so it's techncially faster to use the 2nd argument in this case, because not invoking __newindex is one less function call.

0

Proceeds to ignore what i say and links to the same thing they already said. I've already seen both the links you sent. Still doesn't make my argument invalid.

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