Hello!
I am making a system where it will start spinning something, spin it until a variable is changed, then stop 1 of the 4 tweens that it could be doing and playing a END tween that will smoothly bring it to a stop. This should be pretty simple by the sounds of it but for me it’s not working.
I am using local functions to Start and Stop the spinning and while loops to keep the tweens running.
All my code does is spin the object correctly then when it comes to stop it just stops on the spot, goes backwards a tween, goes forwards a tween, stops without doing the end tween for a couple of seconds then just carry’s on with it’s normal while loop cycle.
Here is my script:
local TweenService = game:GetService("TweenService")
local spinActive = false
local middle1Active = false
local middle2Active = false
local middle3Active = false
local middle4Active = false
local function ENDSpinRide()
wait()
if middle1Active then
spinActive = false
spinPartMIDDLE1Tween:Cancel() spinPartENDTween:Play()
middle1Active = false
end
if middle2Active then
spinActive = false
spinPartMIDDLE2Tween:Cancel() spinPartENDTween:Play()
middle2Active = false
end
if middle3Active then
spinActive = false
spinPartMIDDLE3Tween:Cancel() spinPartENDTween:Play()
middle3Active = false
end
if middle4Active then
spinActive = false
spinPartMIDDLE4Tween:Cancel() spinPartENDTween:Play()
middle4Active = false
end
end
local function STARTspinRide()
spinPartSTART1Tween:Play()
spinPartSTART1Tween.Completed:Connect(function()spinPartSTART2Tween:Play() end)
spinPartSTART2Tween.Completed:Connect(function()spinPartMIDDLE1Tween:Play() middle1Active = true end)
while spinActive do
wait()
spinPartMIDDLE1Tween.Completed:Connect(function()spinPartMIDDLE2Tween:Play() if middle1Active then middle1Active = false middle2Active = true end end)
spinPartMIDDLE2Tween.Completed:Connect(function()spinPartMIDDLE3Tween:Play() if middle2Active then middle2Active = false middle3Active = true end end)
spinPartMIDDLE3Tween.Completed:Connect(function()spinPartMIDDLE4Tween:Play() if middle3Active then middle3Active = false middle4Active = true end end)
spinPartMIDDLE4Tween.Completed:Connect(function()spinPartMIDDLE1Tween:Play() if middle4Active then middle4Active = false middle1Active = true end end)
if not spinActive then
wait()
print("Stopping Spinning")
break
else
return
end
end
end
button.MouseClick:Connect(function()
spinActive = true
wait(1)
STARTspinRide()
wait(20)
print("Stopping")
ENDSpinRide()
end)
Sorry if this code is messy this is the only way I knew how to do this at this point in time.
Thanks ![]()