HELP! Tween Only One Time Playing

  1. What do you want to achieve? I Want to rotating a weld

  2. What is the issue? https://gyazo.com/c1e9285ab9d712c4bb41e9408c5a8193

  3. 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

4th argument of TweenInfo is how many times its gonna be repeated, I believe if you set it to -1 it should be infinite.

i no want infinite example:

repeat 

            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)
            tween:Play()
            tween.Completed:Wait()

            local info2 = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out) 
            local properties2 = {C0 = CFrame.Angles(math.rad(0), 0, math.rad(0))} 
            local tween2 = ts:Create(newWeld, info, properties)
            tween2:Play()
            tween2.Completed:Wait()

            local info3 = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out) 
            local properties3 = {C0 = CFrame.Angles(math.rad(-180), 0, math.rad(180))} 
            local tween3 = ts:Create(newWeld, info, properties)
            tween3:Play()
            tween3.Completed:Wait()

        until not newPart.Parent

Hi! A few things:

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. :slight_smile: 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.