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")