belalg1
(belol)
October 1, 2020, 2:28pm
1
I am trying to make a part rotate 360 deg using tween service, what I know that tween service works like animation so if write this script:
local TweenSettings = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, false, 0)
local Tween = TweenService:Create(part, TweenSettings, {CFrame = part.CFrame * CFrame.Angles(0,-math.rad(360),0)})
Tween:Play()
from what I understand the part should rotate 360 deg in 10 seconds but it’s not working (the part not rotating, I think that the part makes 360 deg multiple times in 10 seconds), so I want to understand how tween service work? and can I make the part rotate 360 deg in a specific time?
2 Likes
ram4c
(ram4c)
October 1, 2020, 2:40pm
2
I think this may work
TweenService = game:GetService("TweenService")
spininfo = TweenInfo.new(2,Enum.EasingStyle.Linear)
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)})
Spin1:Play()
Spin1.Completed:Connect(function()Spin2:Play() end)
Spin2.Completed:Connect(function()Spin3:Play() end)
Spin3.Completed:Connect(function()Spin1:Play() end)
4 Likes
I don’t think setting 3 connections for just rotating a part 360 degrees is good for performance.
1 Like
belalg1
(belol)
October 1, 2020, 2:53pm
4
this may work specifically, but for example if i am trying to make the part rotate 360 deg in 8 second how can I do that ?
1 Like
You could use this
while true do
wait()
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0.1,0,0)
end
You could play around with the CFrame.fromEulerAnglesXYZ and change the values to make the speed faster or slower.
2 Likes
belalg1
(belol)
October 1, 2020, 2:56pm
6
yes but the problem that in this case this will make it laging because of the while true, so im trying to use tween service
1 Like
LordMerc
(Merc)
October 1, 2020, 2:57pm
7
Are you trying to make it spin once?
1 Like
I’m pretty sure will not lag with a while loop if you are not placing too much functions inside the loop
1 Like
belalg1
(belol)
October 1, 2020, 3:00pm
9
No, it’s in a loop (RepeatCount is -1) but I want it to make 360 deg then start again
1 Like
LordMerc
(Merc)
October 1, 2020, 3:04pm
10
If you’re looping it, just use HeartBeat and change it’s rotation by a tiny bit.
1 Like
belalg1
(belol)
October 1, 2020, 3:11pm
11
I want to use tween service because there is a lot of part in my game that must rotate and using HeartBeat will make the game lagging
1 Like
I don’t use TweenInfo’s fourth and further parameters, so try this:
local TweenSettings = TweenInfo.new(10, Enum.EasingStyle.Linear)
local Tween = TweenService:Create(part, TweenSettings, {CFrame = part.CFrame * CFrame.Angles(0,-math.rad(360),0)})
Tween:Play()
1 Like
belalg1
(belol)
October 1, 2020, 3:23pm
13
local TweenSettings = TweenInfo.new(10, Enum.EasingStyle.Linear)
in this case, it will not be in a loop
1 Like
Oh, you wanted to make it loop?
1 Like
belalg1
(belol)
October 1, 2020, 3:38pm
15
yes and make it rotate one time, 360 deg in 10 seconds after that start the loop again
1 Like
LordMerc
(Merc)
October 1, 2020, 3:48pm
16
You don’t know what causes lag I assume since tween service is using HeartBeat…
1 Like
You can do,
local TweenSettings = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, false, 0)
local partProperties = {
Rotation = 360 --Desired Rotation
}
}
local Tween = TweenService:Create(part, TweenSettings, partProperties)
Tween:Play()
Nope, because the starting angular position is the same as the final (0 degrees = 360 degrees) the frame will not rotate, you need to split it up into 2 or more tweens
It is the same, but he wants it to be the same or rotate another 360? If so just added 360 + 360,
local TweenSettings = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, false, 0)
local partProperties = {
Rotation = 360 + 360 --Desired Rotation
}
}
local Tween = TweenService:Create(part, TweenSettings, partProperties)
Tween:Play()
Again, 0, 360, and 720 degrees are all coterminal angles , meaning they hold the same angle. TweenService will interpret the 360 + 360 as an angle of 0, which is the starting position. This prevents the frame from moving at all.