Spinning a part using tween service

local tweenService = game:GetService("TweenService")
local spin = script.Parent

local info = TweenInfo.new(
	3, -- Length (seconds)
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	-1, -- times repeared
	false, -- reverse
	0 -- delay
	
)

local Goals = 
{
	Orientation = Vector3.new(0,0,360);
}

local moveUlapTween =  tweenService:Create(spin, info, Goals)
wait(1)
moveUlapTween:Play()

I tried to spin a part using tween service but i looks like a drunk killbrick
how can i spin a part continously using tween service
I don’t wanna try using while loop then orientation because some players are lagging because of it

3 Likes

I’m confused, what’s wrong with the code you have right now?

robloxapp-20200907-1706242.wmv (1.1 MB)

Here is the video of the drunk killpart

Tween it twice, once 180 degrees, and another time 180 degrees right after the first tween finishes

1 Like

can you send a sample script i don’t know how

local tweenService = game:GetService("TweenService")
local spin = script.Parent

local info = TweenInfo.new(
	3, -- Length (seconds)
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	-1, -- times repeared
	false, -- reverse
	0 -- delay
	
)

local Goals = 
{
	Orientation = Vector3.new(0,0,180);	
}
local Goals2 = 
{
	Orientation = Vector3.new(0,0,360)
}

local moveUlapTween =  tweenService:Create(spin, info, Goals)
local moveUlapTween2 =  tweenService:Create(spin, info, Goals2)
wait(1)
moveUlapTween:Play()
moveUlapTween2:Play()

i tried this but this doesn’t work its stil the same

I made wind turbines that spin forever, and found out you’re better off using a weld between two parts, and Tweening the weld’s C1 or C0, for ease and to be able to move the object mid tween.

Even if you do it straight on the part, the process is the same.

Create three CFrames - the first being at 120 degrees off, the second being 240 degrees off and the third back at the original orientation.

Tween to the first, listen for Tween.Completed event. Tween to the next, listen for Tween.Completed event.

There is absolutely no harm doing this inside of a while loop whilst you want it to keep spinning. You can put the properties into an array, increment a counter, and pick from the array for the next goal.

local TweenService = game:GetService( 'TweenService' )
local spin = script.Parent

local spinning = true
local goals = {}
local tweenInfo = TweenInfo.new(
	3, -- Length (seconds)
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out
)

goals[ 1 ] = spin.CFrame * CFrame.Angles( 0, math.rad( 120 ), 0 )
goals[ 2 ] = spin.CFrame * CFrame.Angles( 0, math.rad( 240 ), 0 )
goals[ 3 ] = spin.CFrame

local i = 0
while spinning do
    i = i % #goals + 1

    local tween = TweenService:Create( spin, tweenInfo, { CFrame = goals[ i ] } )
    tween:Play()

    local state = tween.Completed:Wait()
    if state == Enum.PlaybackState.Cancelled then
        warn( 'Tween cancelled' )
        break
    end
end

So you start the next tween as the previous one finishes. You’re better off using CFrame as it won’t do strange things when reaching 360 degrees whereas Orientation probably will due to it not being a CFrame and not having the same lerping abilities.

I’m on mobile so I can’t watch your video, but if it turns out you want this spinner to be able to move position, and that’s why you only messed with Orientation, then use the welding method mentioned before, and swap out spin.CFrame for Weld.C0 or Weld.C1.

2 Likes

I tried this but it doesn’t work because it resets even thought it didn’t reached one full spin

Apologies, you’ll need to remove the -1 from the TweenInfo - I forgot about the fact it’ll be trying to repeat the old tweens. I’ve updated my original reply accordingly.

1 Like

it gets an error like this if i remove the negative 1

  19:07:00.865 - TweenInfo.new fourth arg should be a number for RepeatCount.
19:07:00.867 - Stack Begin
19:07:00.867 - Script 'Workspace.Obbys.Pink.Laser.Script', Line 6
19:07:00.868 - Stack End

You can’t actually remove that argument since it’s required in the tweenInfo. What you do instead is set it to 0.

1 Like

yeah but he told me to remove the negative 1 which i did
also btw i figured out the answer to this problem thank you all for helping

1 Like