So basically, I want a clean way to fix my tweening as it’s pretty awful right now.
If you watch the video you can see how inconsistent it is, as some parts don’t follow the main path intended. I’ve tried tweening the PrimaryPart. note that there are a lot of WeldConstraints I added which I thought would make this process easier to do, but to no avail. I may have done it wrong though.
Current Hierarchy. (Everything is welded to the PrimaryPart.)
What I really want to happen is this.
A smooth tween. I just wanna know how to move it, but any advice on how I can better my transparency tween is welcome.
CURRENT CODE
local info = TweenInfo.new(math.random(1.2,1.6), Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
for _, v in pairs(rightArm:GetDescendants()) do
if v:IsA("BasePart") then
local goal = {}
goal.CFrame = v.CFrame * CFrame.new(0, math.random(-4,-2), 0)
--goal.Transparency = 1
local tween = TweenService:Create(v, info, goal)
tween:Play()
end
end
It seems this flew right over your head, as your suggestion gives this.
I don’t know about you, but this looks awful to me.
CODE
local info = TweenInfo.new(math.random(1.2,1.6), Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
do
local goal = {}
goal.CFrame = rightArm.PrimaryPart.CFrame * CFrame.new(0, -4, 0)
local tween = TweenService:Create(rightArm.PrimaryPart, info, goal)
tween:Play()
end
Don’t set the CFrame of the part itself, use :SetPrimaryPartCFrame() Here’s what I did on a box, and it moves the entire model.
local part = script.Parent
for i = 1, 1009999 do
wait(0.2)
part:SetPrimaryPartCFrame(part.Center.CFrame + Vector3.new(0,0,1))
wait(0.2)
part:SetPrimaryPartCFrame(part.Center.CFrame + Vector3.new(0,-0,-1))
end
I requested TweenService as the answer, a for loop would work, but the implementation wouldn’t be clean as I asked.
Also, the code you provided is pretty bad.
local part = script.Parent
for i = 1, 1009999 -- why did you think using huge values like this, a good idea? do
wait(0.2)
part:SetPrimaryPartCFrame(part.Center.CFrame + Vector3.new(0,0,1)) -- aren't you supposed to multiply?
wait(0.2)-- why is it waiting twice?
part:SetPrimaryPartCFrame(part.Center.CFrame + Vector3.new(0,-0,-1))
end
Since tweening is for the properties of instances, you can’t really tween a whole model by itself. What you could do is create a CFrameValue object as a placeholder for the primary part and tween that. Then listen for changes in that value and use SetPrimaryPartCFrame on the model.
You can create a NumberValue, set the Value of that to 0 and then tween it to 1 with the correct easing style, easing direction etc.
Then you can use GetPropertyChangedSignal to get when the value changes and lerp the model CFrame to the new cframe
Here’s my code.
function TweenModel(Model,NewPrimaryPartCFrame)
local FloatValue = Instance.new("NumberValue")
FloatValue.Value = 0
local Tween = TweenService:Create(FloatValue,TweenInfo.new(0.1,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false,0),{Value = 1})
Tween:Play()
local Change = FloatValue:GetPropertyChangedSignal("Value"):Connect(function()
local NewCFrame = Model.PrimaryPart.CFrame:Lerp(NewPrimaryPartCFrame,FloatValue.Value)
Model:SetPrimaryPartCFrame(NewCFrame)
end)
Tween.Completed:Connect(function()
Tween:Destroy()
Change:Disconnect()
FloatValue:Destroy()
end)
end
wait(10)
local TweenService = game:GetService("TweenService")
local part = script.Parent
local info = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
do
local goal = {}
goal.CFrame = part.PrimaryPart.CFrame * CFrame.new(0, 0, 20)
goal.Transparency = 0.1
local tween = TweenService:Create(part.PrimaryPart, info, goal)
tween:Play()
print("played tween")
end
For your response, I wasn’t saying to use huge number values such as “1009999”. I waited twice because I wanted to see if it would properly move backward and forwards. And you can add vector values to CFrame.
Here’s what I did to my box model and it worked perfectly fine. Here’s also video proof.
I hope that this will work for you, and if not I apologize.
I DID IT! I found out a cleaner solution without having to use long winded lines of code like this.
local TweenService = game:GetService("TweenService")
local Model = workspace.Model
local Info = TweenInfo.new()
local PrimaryPartDestination = Vector3.new()
for i,Part in pairs(Model:GetChildren()) do
local Tween = TweenService:Create(Part,Info,{CFrame = CFrame.new((Part.Position-Model.PrimaryPart.Position)+PrimaryPartDestination)})
Tween:Play()
end
or this
function TweenModel(Model,NewPrimaryPartCFrame)
local FloatValue = Instance.new("NumberValue")
FloatValue.Value = 0
local Tween = TweenService:Create(FloatValue,TweenInfo.new(0.1,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false,0),{Value = 1})
Tween:Play()
local Change = FloatValue:GetPropertyChangedSignal("Value"):Connect(function()
local NewCFrame = Model.PrimaryPart.CFrame:Lerp(NewPrimaryPartCFrame,FloatValue.Value)
Model:SetPrimaryPartCFrame(NewCFrame)
end)
Tween.Completed:Connect(function()
Tween:Destroy()
Change:Disconnect()
FloatValue:Destroy()
end)
end
It was quite simple actually, basically you weld all the parts in a model to the PrimaryPart, then make sure every other part is un-anchored making the PrimaryPart the only anchored part. Then in your code you can do this,
local info = TweenInfo.new(math.random(1.2,1.6), Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
do
local goal = {}
goal.CFrame = rightArm.PrimaryPart.CFrame * CFrame.new(0, -4, 0)
goal.Transparency = 1
local tween = TweenService:Create(rightArm.PrimaryPart, info, goal)
tween:Play()
tween.Completed:Connect(function()
rightArm:Destroy()
end)
end
It was actually easy as pie. Result below.
Not fully polished, but it looks WAAY better than before.