imskyyc
(imskyyc)
May 7, 2020, 6:35pm
#1
So, I have a function that tweens a door model out, waits some time, then in. Here it is:
local Move = function(Model, ToCFrame, TimeOfDelay)
if Mode == "Fast" then
wait(TimeOfDelay)
Model:SetPrimaryPartCFrame(ToCFrame)
elseif Mode == "Tween" then
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = Model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
Model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local Info = TweenInfo.new(TimeOfDelay, Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0)
local Tween = game:GetService("TweenService"):Create(CFrameValue, Info, {Value = ToCFrame})
Tween:Play()
Self = Tween.Completed:Connect(function()
CFrameValue:Destroy()
Self:Disconnect()
end)
wait(TimeOfDelay)
end
end
robloxapp-20200507-1121421.wmv (2.8 MB)
Anybody know what I did wrong?
1 Like
imskyyc
(imskyyc)
May 7, 2020, 6:53pm
#2
Issue is fixed. Some of the parts were not anchored.
1Joeb
(joeberson)
May 7, 2020, 7:13pm
#3
Make sure to mark as solved so we know that it is from the main page.
Not exactly on topic but I recommend tweening your model by welding all related parts to it as opposed to using this method. I have a tutorial on model tweening which explains some of the downfalls of this practice. See here:
Edit (06/30/2021): Due to the release of the new pivot APIs and the thankful deprecation of SetPrimaryPartCFrame, the legacy method of CFraming is now also appropriate and you do not necessarily need to use this welding method. Do note that the pivot CFrame is different from the PrimaryPart CFrame though, so you will have to account for that when writing your proxy objects.
Edit (05/31/2023): Roblox has an official code sample for model tweening! It’s very lightweight and covers the necessities…
tl;dr - SetPrimaryPartCFrame is bad when called in excess.
1 Like