i want to achieve that my TweenService Animation reverse after 30 seconds
and if the Player Clicks the button Again the whole animation starts from new.
i tried so far looking on Youtube how other make ther script but i did not find a solution how to do it in my script because for some reason my Script looks completely different
Anyways here is my Script
local onCooldown = false
script.Parent.MouseClick:Connect(function(click)
if onCooldown == false then
onCooldown = true
local TweenService = game:GetService("TweenService")
local part = workspace.General.Button
part.Position = Vector3.new(-3.417, 4.065, -15.827)
part.Color = Color3.new(0, 1, 0)
part.Anchored = true
part.Parent = game.Workspace.General
local goal = {}
goal.Position = Vector3.new(-3.417, 4.001, -15.827)
goal.Color = Color3.new(1, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.delay(30, function()
onCooldown = false
end)
end
end)
if anyone have a solution for the i would be very happy to hear it. and sorry if i did anything rong in this post.
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
Using the “reverse” parameter for TweenInfo won’t work because it reverses as soon as the tween finishes, regardless of DelayTime. What you have to do is make two tweens, one for tweening the part’s position and color to the goal, and then another for tweening it back to how it was.
local TweenService = game:GetService("TweenService")
local part = workspace.General.Button
part.Position = Vector3.new(-3.417, 4.065, -15.827)
part.Color = Color3.new(0, 1, 0)
part.Anchored = true
part.Parent = game.Workspace.General
local goal = {} --This is the goal for the first tween
goal.Position = Vector3.new(-3.417, 4.001, -15.827)
goal.Color = Color3.new(1, 0, 0)
local reverseGoal = {} --This is the goal for the reverse tween
reverseGoal.Position = part.Position
reverseGoal.Color = part.Color
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(part, tweenInfo, goal) --This is the first tween
local reverseTween = TweenService:Create(part, tweenInfo, reverseGoal) --This is the tween that reverses it back to normal
tween:Play()
wait(30) --Wait for 30 seconds
reverseTween:Play() --Now play the tween that reverts it to how it was before
If you need it to reverse after 30 seconds then instead of using the “reverse” parameter of the instance method :Create() just create an additional tween which performs the reverse of the initial tween after thirty seconds have elapsed.
What exactly doesn’t work about it? It’s supposed to play the first tween, y’know, moving the part and shifting the color, then after 30 seconds, it plays another tween, which makes it move back to where it initially was and changes the color back to normal.
If it’s the reverse tween that’s not working, perhaps set the position and color of reverseGoal differently than how I did it.
local reverseGoal = {} --This is the goal for the reverse tween
reverseGoal.Position = Vector3.new(-3.417, 4.065, -15.827)
reverseGoal.Color = Color3.new(0, 1, 0)
Now it works but if i click the button again after 30 seconds it doesn’t work anymore.
local onCooldown = false
script.Parent.MouseClick:Connect(function(click)
if onCooldown == false then
onCooldown = true
local TweenService = game:GetService("TweenService")
local part = workspace.General.Button
part.Position = Vector3.new(-3.417, 4.065, -15.827)
part.Color = Color3.new(0, 1, 0)
part.Anchored = true
part.Parent = game.Workspace.General
local goal = {} --This is the goal for the first tween
goal.Position = Vector3.new(-3.417, 4.001, -15.827)
goal.Color = Color3.new(1, 0, 0)
local reverseGoal = {} --This is the goal for the reverse tween
reverseGoal.Position = part.Position
reverseGoal.Color = part.Color
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(part, tweenInfo, goal) --This is the first tween
local reverseTween = TweenService:Create(part, tweenInfo, reverseGoal) --This is the tween that reverses it back to normal
tween:Play()
wait(30) --Wait for 30 seconds
reverseTween:Play() --Now play the tween that reverts it to how it was before
task.delay(30, function()
onCooldown = false
end)
end
end)
i apologize i did make a little mistake in the script i did now fix it the script looks like this
local onCooldown = false
script.Parent.MouseClick:Connect(function(click)
if onCooldown == false then
onCooldown = true
local TweenService = game:GetService("TweenService")
local part = workspace.General.Button
part.Position = Vector3.new(-3.417, 4.065, -15.827)
part.Color = Color3.new(0, 1, 0)
part.Anchored = true
part.Parent = game.Workspace.General
local goal = {} --This is the goal for the first tween
goal.Position = Vector3.new(-3.417, 4.001, -15.827)
goal.Color = Color3.new(1, 0, 0)
local reverseGoal = {} --This is the goal for the reverse tween
reverseGoal.Position = part.Position
reverseGoal.Color = part.Color
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(part, tweenInfo, goal) --This is the first tween
local reverseTween = TweenService:Create(part, tweenInfo, reverseGoal) --This is the tween that reverses it back to normal
tween:Play()
task.delay(30, function()
onCooldown = false
wait(30) --Wait for 30 seconds
reverseTween:Play() --Now play the tween that reverts it to how it was before
end)
end
end)