Hey there, I’m trying to make a crate opening animation thing but ran into some trouble when trying reverse the reverse the value, not back to its original value but negtive.
Basically the base value is 0 and it goes to 30 then back down to 0 but I want it to go to negative 30 if that makes sense.
Any help is very much apricated!
Script: (theres some code above that isnt relative by the way.)
local function Shake()
local Speed = .4
local tweenInfo = TweenInfo.new(
Speed, -- Speed obviously
Enum.EasingStyle.Linear, -- Style
Enum.EasingDirection.InOut, -- Direction
5, -- times repeated
true, -- Reverse
0 -- Delay
)
local tween = TweenService:Create(part, tweenInfo, {Orientation = Vector3.new(0,0,30)}) -- 30 is the value I want to change to -30 after it reaches 30
tween:Play()
end
wait(5)
Shake()
local TweenConn
local function Shake()
local Speed = .4
local tweenInfo = TweenInfo.new(
Speed, -- Speed obviously
Enum.EasingStyle.Linear, -- Style
Enum.EasingDirection.InOut, -- Direction
5, -- times repeated
true, -- Reverse
0 -- Delay
)
local tween = TweenService:Create(part, tweenInfo, {Orientation = Vector3.new(0,0,30)}) -- 30 is the value I want to change to -30 after it reaches 30
tween:Play()
TweenConn = tween.Completed:Connect(function()
TweenConn:Disconnect()
TweenConn = nil
TweenService:Create(part, tweenInfo, {Orientation = Vector3.new(0,0,-30)}):Play()
end
end
wait(5)
Shake()
That just does it one dierction 5 times then the other dierction 5 time, sorry if I wasnt clear but I meant all in the same motion so like it goes 30 degrees then -30 degrees then repeats that 5 times, Sorry.
local function Shake()
local Speed = .4
local TimesToRotate = 5
local tweenInfo = TweenInfo.new(
Speed, -- Speed obviously
Enum.EasingStyle.Linear, -- Style
Enum.EasingDirection.InOut, -- Direction
5, -- times repeated
true, -- Reverse
0 -- Delay
)
local tween = nil
for i = 1, TimesToRotate do
tween = TweenService:Create(part, tweenInfo, {Orientation = Vector3.new(0,0,30)}) -- 30 is the value I want to change to -30 after it reaches 30
tween:Play()
tween.Completed:Wait()
tween = TweenService:Create(part, tweenInfo, {Orientation = Vector3.new(0,0,-30)})
tween.Completed:Wait()
end
tween = TweenService:Create(part, tweenInfo, {Orientation = Vector3.new(0,0,0)}) -- 30 is the value I want to change to -30 after it reaches 30
tween.Completed:Wait()
end
The current code would rotate it by 30 degrees and would then rotate to -30 and I added a variable “TimesToRotate” which you can say how much times do you want it to rotate before going to it’s normal position 0.
-- Constants
local SPEED = .4
local REPEAT = 5 -- Times you want it to repeat
local Tweeninfo = TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true)
local function Shake()
local Tween
for _ = 1, REPEAT do
Tween = TweenService:Create(part, Tweeninfo, {Orientation = Vector3.new(0,0,30)})
Tween:Play()
Tween.Completed:Wait()
Tween = TweenService:Create(part, Tweeninfo, {Orientation = Vector3.new(0,0,-30)})
Tween:Play()
Tween.Completed:Wait()
end
end
Just one more thing, If I wanna increase the speed each time so that the final time it does it the speed would be like .05 how would I go about doing that?
-- Constants
local SPEED = .4
local REPEAT = 5 -- Times you want it to repeat
local Tweeninfo = TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true)
local function Shake()
local Tween
for i = 1, REPEAT do
if i == REPEAT then -- If the current Iteration is the last one
Tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true)
end
Tween = TweenService:Create(part, Tweeninfo, {Orientation = Vector3.new(0,0,30)})
Tween:Play()
Tween.Completed:Wait()
Tween = TweenService:Create(part, Tweeninfo, {Orientation = Vector3.new(0,0,-30)})
Tween:Play()
Tween.Completed:Wait()
end
end
All you have to do is check what i is and if its the same as repeat it means its on the last run and in there you would simply change the tweeninfo to the new speed
-- Constants
local REPEAT = 5 -- Times you want it to repeat
-- Var
local SPEED = .4
local function Shake()
local Tween
for i = 1, REPEAT do
if i == REPEAT then -- If the current Iteration is the last one
SPEED = 1
end
Tween = TweenService:Create(part, TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true), {Orientation = Vector3.new(0,0,30)})
Tween:Play()
Tween.Completed:Wait()
Tween = TweenService:Create(part, TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true), {Orientation = Vector3.new(0,0,-30)})
Tween:Play()
Tween.Completed:Wait()
end
end
Maybe something like this though I’m not sure why the other one does work.