What solutions have you tried so far? Did you look for solutions on the Developer Hub?
local newModel = Instance.new("Model",game.Workspace)
newModel.Name = "WaterPrisonModel"
local newPart = Instance.new("Part",newModel)
newPart.CFrame = char.PrimaryPart.CFrame
local newWeld = Instance.new("Weld",newPart)
newWeld.Part0 = newPart
newWeld.Part1 = char.PrimaryPart
local info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local properties = {C0 = CFrame.Angles(math.rad(180), 0, math.rad(-180))}
local tween = ts:Create(newWeld, info, properties)
while true do
tween:Play()
tween.Completed:Wait()
end
You tween the weld c0 to some angle. Once it is completed, tweening again to that same angle will change nothing: it already is in that angle!
Instead of using a while true loop, tweens have the ability to loop, either starting over or tweening back and forth. This can be done using tweeninfo.repeatcount and tweeninfo.reverses.
Sometimes rotating stuff with tweens can be tricky, as turning one way or the other will achieve the same end result (and the end-result is the only thing specified to the tween, such that 360 degrees is the same as 0 degrees). It seems math.rad conserves the extra rotations, but I’m pretty sure the CFrame doesn’t. I’m guessing that it’s possible to do this way (tweening the weld C0 CFrame) but that it will need multiple tweens to do a full rotation. Good luck!
So yeah as you say, you should be able to so something like:
local info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local properties = {}
local degrees = 0
local toggle = true
task.spawn(function()
while toggle do
degrees = (degrees + 120) % 360
properties["C0"] = CFrame.Angles(math.rad(degrees), 0, math.rad(-degrees))
local tween = ts:Create(newWeld, info, properties)
tween:Play()
tween.Completed:Wait()
end
end)
Or just premake all tweens, then loop. By putting it inside spawn() you can still do other things in the script, such as toggle off the loop when done.
local steps = 3
--local stepSize = math.rad(360/steps)
local stepSize = math.pi*2/steps
local info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tweens= {}
for i = 1, steps do
local angle = i*stepSize
local properties = {C0 = CFrame.Angles(angle, 0, -angle)}
local tween = ts:Create(newWeld, info, properties)
table.insert(tweens, tween)
end
local counter = 0
local toggle = true
task.spawn(function()
while toggle do
counter = (counter) % steps + 1
local currentTween = tweens[counter]
currentTween:Play()
currentTween.Completed:Wait()
end
end)
This way, you have less duplicated code, and the last one prevents some unnecessary operations and lets you set the amount of steps to make a full turn. Not really necessary here but it may be a helpful example.