Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to move a model using TweenService?

Asked by 5 years ago

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

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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
0
Instance.new("class",parent) is deprecated. use local obj = Instance.new("class") obj.Parent = parent yHasteeD 1819 — 5y
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. Amiaa16 3227 — 5y
0
https://wiki.roblox.com/index.php?title=Instance_(Data_Structure) also: https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296 I just wanted to show the links yHasteeD 1819 — 5y
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. Amiaa16 3227 — 5y
Ad

Answer this question