Issue with a Carousel not spinning fully

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Making a carousel that only spins when a value is true
  2. What is the issue? Include screenshots / videos if possible!
    when the value is set to true it spins for about 5 seconds then stops
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have moved around the script but haven’t done much because am a little confused

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Val = script.Parent.Parent.Parent.Value


TweenService = game:GetService("TweenService")
spininfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
Spin1 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(120),0,0)})
Spin2 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(120),0,0)})
Spin3 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(120),0,0)})


while true do
	wait(0.05)
	if Val.Value == true then
		print("value is true")
		Spin1:Play()
		while true do
			wait(0.05)
			

			Spin1.Completed:Connect(function()Spin2:Play() end)
			print("2 playing")
			Spin2.Completed:Connect(function()Spin3:Play() end)
			print("3 playing")
			Spin3.Completed:Connect(function()Spin1:Play() end)
			print("1 playing")
		end
	end
end

the 3 spins are to give the illusion of spinning 360 multiple times but I’m not sure if that is the most efficient way of doing it. Any help is a apprieciated
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

First things first, get rid of the first while loop and change the second part of your code to:

Val.Changed:Connect(function()
    if Val.Value == true then
		print("value is true")
		Spin1:Play()
		while true do
			task.wait(0.05)
			

			Spin1.Completed:Connect(function()Spin2:Play() end)
			print("2 playing")
			Spin2.Completed:Connect(function()Spin3:Play() end)
			print("3 playing")
			Spin3.Completed:Connect(function()Spin1:Play() end)
			print("1 playing")
		end
	end
end)

Now I ask what is the point of the next while loop

well for the first one I didn’t want the value to only be checked once and for the second one I didn’t want the spinning to stop until the value was false (ABout 40 seconds after its set to true

It’s not only being checked once, but it’s being check Everytime it changes.

Use a repeat wait loop until Val.Value == false
So now that part of the script should be:

Val.Changed:Connect(function()
    if Val.Value == true then
		print("value is true")
		Spin1:Play()
        repeat task.wait(0.05)
		    Spin1.Completed:Connect(function()Spin2:Play() end)
			print("2 playing")
			Spin2.Completed:Connect(function()Spin3:Play() end)
			print("3 playing")
			Spin3.Completed:Connect(function()Spin1:Play() end)
			print("1 playing")
		until Val.Value == false
	end
end)

where it says until it errors saying it expects an end because of the do

Oops try it now I didn’t mean to add the do

so I have your version of the script but I have the same issue where it rotates like 180 degrees then stops. I tried using the rotating tween on a normal part and it seems to work but it stops on the actual carousel.

What if you try to only use one tween that tweens to 360 degrees rotation, and lasts like 15 seconds (5x3)

this is the script I have now and its still now working

local Val = script.Parent.Parent.Parent.Value


TweenService = game:GetService("TweenService")
spininfo = TweenInfo.new(7,Enum.EasingStyle.Linear)
Spin1 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(120),0,0)})



Val.Changed:Connect(function()
	if Val.Value == true then
		if Val.Value == true then
			print("value is true")
			Spin1:Play()
			repeat task.wait(0.05)
				Spin1.Completed:Connect(function()Spin1:Play() end)
			until Val.Value == false end
	end		
end)
	

I don’t recommend using tweens for this, instead on the client use a RunService like so:

local RunService = game:GetService("RunService")
local RotationSpeed = 5

local Carousel = DEFINE

RunService.Heartbeat:Connect(function(dt)
    Carousel.CFrame *= CFrame.Angles(math.rad(RotationSpeed * dt), 0, 0)
end)
1 Like

In this case it is more appropriate to use Wait instead of Connect. Also, all targets are set to 120 degrees from the initial rotation when they should be 120, 240 and 360.

local Val = script.Parent.Parent.Parent.Value

TweenService = game:GetService("TweenService")
spininfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
Spin1 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(120),0,0)})
Spin2 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(120*2),0,0)})
Spin3 = TweenService:Create(script.Parent,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(120*3),0,0)})

while true do
	wait(0.05)
	if Val.Value == true then
		print("value is true")
		while true do
			Spin1:Play()
			print("1 playing")
			Spin1.Completed:Wait()
			Spin2:Play() 
			print("2 playing")
			Spin2.Completed:Wait()
			Spin3:Play() 
			print("3 playing")
			Spin3.Completed:Wait()
		end
	end
end

I hope this was helpful.

this seems to work although it doesnt stop when the value is set back to false

local RunService = game:GetService("RunService")
local RotationSpeed = 2
local Val = script.Parent.Parent.Parent.Value

local Carousel = script.Parent



Val.Changed:Connect(function()
	if Val.Value == true then
		if Val.Value == true then
			print("value is true")
			repeat task.wait(1)
				RunService.Heartbeat:Connect(function(dt)
					Carousel.CFrame *= CFrame.Angles(math.rad(RotationSpeed * dt), 0, 0)
				end)
			until Val.Value == false end
	end		
end)

Change that to:

RunService.Heartbeat:Connect(function(dt)
    if Val.Value then
		Carousel.CFrame *= CFrame.Angles(math.rad(RotationSpeed * dt), 0, 0)
	end)
end
1 Like