Trying to play and pause but the tween is ignoring my commands after some time of calling

I am trying to pause and play a rotating tween service. But for some reason it is not working as intended.

While I run this code the following problem arise, The obstacle start playing but after some time of playing and pausing it completely stops pausing and playing why is that happening? I have marked the point with a comment were the rotation just completely stops and ignore my commands

Can someone tell me why this is happening? and possibly ways to fix this problem

TweenService = game:GetService("TweenService")
spininfo = TweenInfo.new(0.8,Enum.EasingStyle.Linear)
local os1 = script.Parent

Spin1 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(120),0)})
Spin2 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(240),0)})
Spin3 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(360),0)})


local function pausingTween()
	Spin1:Pause() 
	Spin1.Completed:Connect(function()Spin2:Pause() end)
	Spin2.Completed:Connect(function()Spin3:Pause() end)
	Spin3.Completed:Connect(function()Spin1:Pause() end)
end


local function playingTween()
	Spin1:Play() 
	Spin1.Completed:Connect(function()Spin2:Play() end)
	Spin2.Completed:Connect(function()Spin3:Play() end)
	Spin3.Completed:Connect(function()Spin1:Play() end)
end


os1:GetAttributeChangedSignal("toActivate"):Connect(function()
	if os1:GetAttribute("toActivate") == true then
		print("Playing")
		playingTween()

	else
		print("Pausing")
		pausingTween() 
	end
end)

wait(10)
os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate"))
wait(5)
os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))
wait(5)
os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate"))
wait(5)
os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))
wait(5)
os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate")) 
--After reaching this point the program stops pausing and playing

wait(5)
os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))
wait(5)
os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate"))
wait(5)
os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))
print("Finished")

Hey, just disconnect the .Completed for each Spin.
I changed your code and if you paste this in will work.

TweenService = game:GetService("TweenService")

spininfo = TweenInfo.new(0.8,Enum.EasingStyle.Linear)

local os1 = script.Parent

Spin1 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(120),0)})

Spin2 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(240),0)})

Spin3 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(360),0)})

local c1 = nil
local c2 = nil
local c3 = nil

local function disc()
 if c1 then
 	c1:Disconnect()
 end
 if c2 then
 	c2:Disconnect()
 end
 if c3 then
 	c3:Disconnect()
 end
end

local function pausingTween()
 disc()
 Spin1:Pause()

 c1 = Spin1.Completed:Connect(function()Spin2:Pause() end)
 c2 = Spin2.Completed:Connect(function()Spin3:Pause() end)
 c3 = Spin3.Completed:Connect(function()Spin1:Pause() end)

end

local function playingTween()
 disc()
 Spin1:Play()

 c1 = Spin1.Completed:Connect(function()Spin2:Play() end)
 c2 = Spin2.Completed:Connect(function()Spin3:Play() end)
 c3 = Spin3.Completed:Connect(function()Spin1:Play() end)
end

os1:GetAttributeChangedSignal("toActivate"):Connect(function()
 if os1:GetAttribute("toActivate") == true then
 	print("Playing")
 	playingTween()
 else
 	print("Pausing")
 	pausingTween()
 end
end)

wait(10)

os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate"))

wait(5)

os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))

wait(5)

os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate"))

wait(5)

os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))

wait(5)

os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate"))

--After reaching this point the program stops pausing and playing

wait(5)

os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))

wait(5)

os1:setAttribute("toActivate", true)
print(os1:GetAttribute("toActivate"))

wait(5)

os1:setAttribute("toActivate", false)
print(os1:GetAttribute("toActivate"))
print("Finished")
1 Like

Thank you this have fixed the problem