I’m trying to make a part spin without stopping using a tween. But when I run it, it looks like the tween plays once and then stops even though it’s inside a loop. What’s the issue here?
local tweenService = game:GetService("TweenService")
local spinPart = script.Parent.SpinPart
local goal = {}
goal.CFrame = spinPart.CFrame * CFrame.Angles(3, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(spinPart, tweenInfo, goal)
while true do
tween:Play()
tween.Completed:Wait()
end
When the Tween finishes, its at its ‘finish’ position. When you start the tweet again, since the part is already at its ‘finish’ position, it won’t move because it’s done already. In your loop you have to define new tween settings.
Not the best with Tweens but pretty sure you gotta write it like this:
local spinPart = script.Parent.SpinPart
while true do
local goal = {}
goal.CFrame = spinPart.CFrame * CFrame.Angles(3, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(spinPart, tweenInfo, goal)
tween:Play()
tween.Completed:Wait()
end
When tween:Play() is done a second time, spinPart has already reached its target. that is why the spinning stops.
the target must be updated on each iteration.
local tweenService = game:GetService("TweenService")
local spinPart = script.Parent.SpinPart
local goal = {}
local tweenInfo = TweenInfo.new(1)
while true do
goal.CFrame = spinPart.CFrame * CFrame.Angles(3, 0, 0)
local tween = tweenService:Create(spinPart, tweenInfo, goal)
tween:Play()
tween.Completed:Wait()
end