I am making a npc do a 180 rotation with tweening. I made it without tweening, and I commented it. Now I made it tween and it doesn’t move. Here is the script:
local Waifu = game.Workspace.ZeroTwo
local hum = script.Parent.Humanoid
local TweenService = game:GetService("TweenService")
local Waifu180Info = TweenInfo.new(10,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)
local Waifu180Tween = TweenService:Create(Waifu.PrimaryPart,Waifu180Info,{CFrame = Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(180),0)})
local WaifuNegative180Tween = TweenService:Create(Waifu.PrimaryPart,Waifu180Info,{CFrame = Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(-180),0)})
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://5606803808"
local track = hum:LoadAnimation(anim)
while true do
wait(4)
--track:Play()
wait(1.09)
print("180")
Waifu180Tween:Play()
--Waifu:SetPrimaryPartCFrame(Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(180),0))
wait(3.07)
print("-180")
WaifuNegative180Tween:Play()
--Waifu:SetPrimaryPartCFrame(Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(-180),0))
wait(0.93)
end
Both these print statements print, but it doesn’t tween.
I have an animation wich plays (it is commented in the script) and it walks and was supposed to turn around and wave their hand, but I couldn’t make it turn 180 because the hats weren’t welded, and when I welded them they sorta glitched, I even asked a question on the forum but got no answers, so I just made it wave the hand and make it rotate in the script. The waits are so it turns around when it waves the hand.
Tweening models have been a very common issue. The most efficient way would be to weld the parts to the PrimaryPart of the model and then tweening solely the primary part. The reason your tween isn’t playing (I’m assuming) is because the parts within the model are unwelded and anchored, so the tween target is only targeting 1 part to tween.
I rewrote your script with a function used to weld the model. Hopefully your tween should play correctly now:
local function weldModel(model)
for _, Part0 in pairs(model:GetDescendants()) do
if Part0:IsA("BasePart") and not (Part0 == model.PrimaryPart) then
local WeldConstraint = Instance.new("WeldConstraint")
WeldConstraint.Part0 = Part0
WeldConstraint.Part1 = model.PrimaryPart
WeldConstraint.Parent = WeldConstraint.Part0
Part0.Anchored = false
end
end
return model
end
local Waifu = weldModel(game.Workspace.ZeroTwo)
local hum = script.Parent.Humanoid
local TweenService = game:GetService("TweenService")
local Waifu180Info = TweenInfo.new(10,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)
local Waifu180Tween = TweenService:Create(Waifu.PrimaryPart,Waifu180Info,{CFrame = Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(180),0)})
local WaifuNegative180Tween = TweenService:Create(Waifu.PrimaryPart,Waifu180Info,{CFrame = Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(-180),0)})
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://5606803808"
local track = hum:LoadAnimation(anim)
while true do
wait(4)
--track:Play()
wait(1.09)
print("180")
Waifu180Tween:Play()
--Waifu:SetPrimaryPartCFrame(Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(180),0))
wait(3.07)
print("-180")
WaifuNegative180Tween:Play()
--Waifu:SetPrimaryPartCFrame(Waifu.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(-180),0))
wait(0.93)
end
Thanks for the reply. After using your welding function, it did really tween. So I went ahead and uncommented the line wich plays the animation, but the animation did not play, only the tween did. Still with your welding function, I commented the lines wich played both the tweens, keeping the line that plays the animation, and it still didn’t work. So I made Waifu be the actual model again, and the animation played. So I think welding somehow affects the animation. Do you know a workaround around this?
Since you’re only rotating the model 180 degrees in both directions, you can make a function that rotates this model incrementally 180 degrees using SetPrimaryPartCFrame, forget about welding the model.
Alright, I used a for loop that goes up to 20 and increments 1 each loop, and I rotated 9 radians each time, and it is actually pretty smooth. Thank you.