Hello,
I’m trying to tween an entire model, but only the PrimaryPart moves, even though the model is welded. Any suggestions?
Hello,
I’m trying to tween an entire model, but only the PrimaryPart moves, even though the model is welded. Any suggestions?
I haven’t tweened models in a while, and I have a very forgetful memory, so I may be wrong. Perhaps you could try YourModel:PivotTo(YourCFrame)
?
Are the welded parts in the model anchored?
local model = "put the model here"
local p = model.PrimaryPart
local ts = game.TweenService
local pos = Vector3.new(position to move to)
local o = Vector3.new(the rotation u want it to be)
for k,v in pairs(model:GetDescendants()) do
if v:IsA("BasePart") and p ~= v then
local weld = Instance.new("Weld")
weld.Part0 = p
weld.Part1 = v
weld.C0 = prim.CFrame:ToObjectSpace(v.CFrame)
weld.Parent = v
v.Anchored = false
end
end
local tinfo = TweenInfo.new(time it should take,easing style, easing direction(optional))
local goal = {
CFrame = CFrame.new(pos.X,pos.Y,pos.Z) * CFrame.Angles(math.rad(o.X),math.rad(o.Y),math.rad(o.Z))
}
local tween = ts:Create(p,tinfo,goal):Play()
this was something quick and dirty, hope this helps.
let me know if u have any questions
no pls no never use that. dont rely on roblox methods for that, tweening allows u to control it much more precisely
I meant tween the whole model using that method, there’s nothing wrong with it…
Should never use the now deprecated Weld
instance. Use the WeldConstraint
instance instead.
There are multiple threads about this topic. I would try searching it up more thoroughly next time.
To tween a model, you weld everything together, and unanchor every part except the one you’re tweening. (likely the primary part) The model will not fall apart because it is welded to the anchored primary part.
After you’ve set this up, try tweening the primary part.
weldconstraints rely on physics (which can be buggy), whereas welds are locked and are much more reliable. ive used that weld script many many times (i made it myself) and have never had issues.
ALSO use CFrame as your tween property or else the part won’t move welded parts along with it, sorry for forgetting about this.
oh lol i forgot about that, i’ll update my code in a sec
Not really, I personlly have had issues with Welds
, maybe they changed since then, I’ll look into it.
yea i messed up the code, gimme 20 minutes and i’ll update it
Just use this:
local TweenService = game:GetService('TweenService')
local function TweenModel<A>(model: Model, Goal: CFrame, time: number, EasingStyle: Enum.EasingStyle?, EasingDirection: Enum.EasingDirection?, callback: ((A...) -> ())?, ...: A...?)
EasingStyle = EasingStyle or Enum.EasingStyle.Linear
EasingDirection = EasingDirection or Enum.EasingDirection.In
local start = model:GetPivot()
time /= 100
coroutine.wrap(function(...)
for t = 0, 1, 0.01 do
local alpha = TweenService:GetValue(t, EasingStyle, EasingDirection)
model:PivotTo(start:Lerp(Goal, alpha))
task.wait(time)
end
if callback then callback(...) end
end)(...)
end