How can I stop this from happening?

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

Increase part.Rotation on the axis of your choice.

I am rotating the part but I am running it through a while loop to carry on running 4 tweens. When i try and stop the while loop and play the end tween it just goes backwards, forwards, just stops, then carry’s on in the whileloop.

I have figured it out now!

This post is now not needed!

Could you share how you fixed it?

I have added a new part into to workspace and put it above the spinning part and made sure it was Anchored. The spinning disc is not Anchored.

I joined the spinning disc with the new part by using a a ManualWeld. This is so I can change the C1 Orientation value in a tween to rotate the spinning discord. If you want more things to spin the spinning discord you can weld them to it with WeldConstraints.

The new part I created that is slight above the spinning disc I duplicated it and called the new part something like Point1. I then make a movingTween which moves the new part up towards Point1. As this is ManualWelded to the spinning disc it allows two tweens to happen at the same time without interference.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.