Hey guys, so I use tweens quite frequently when coding my projects and doing commissions. I love the smooth transitions it provides but I find it makes my code a mess. Tweens take up so many lines and make my code look unreadable.
Furthermore, the “reverse” option when creating a tween is extremely annoying. As far as I’m aware, you can’t delay the reverse. In my scripts, I often want to set reverse to true, but it reverses immediately after the tween finishes. I often want it to wait a set amount of time before reversing. So in order to work around this issue, I have to make a whole TweenInfo, Goal, and Tween just for reversing it.
I will provide a sample of some code below that will allow you to see what I’m talking about. Does anyone know of ways to make tweens look more readable and not jumble up the code? And is there another way to go about reversing a tween that doesn’t involve creating a reverse tween?
A snippet of my code from an ATM system (LocalScript; UI Tweening)
local function onErrorOccurance(message)
confirmDebounce = true
local errorInfo = TweenInfo.new(0.3, Enum.EasingStyle.Linear)
local targetPosition = UDim2.new(0.316, 0,0.216, 0)
local errorTween = TweenService:Create(errorGui.Background, errorInfo, {Position = targetPosition})
local errorInfoReverse = TweenInfo.new(0.3, Enum.EasingStyle.Linear)
local targetPositionReverse = UDim2.new(-0.4, 0,0.216, 0)
local errorTweenReverse = TweenService:Create(errorGui.Background, errorInfoReverse, {Position = targetPositionReverse})
local confirmButtonInfo = TweenInfo.new(0.3, Enum.EasingStyle.Linear)
local confirmButtonTween = TweenService:Create(confirm, confirmButtonInfo, {BackgroundColor3 = errorColor})
local confirmButtonInfoReverse = TweenInfo.new(0.3, Enum.EasingStyle.Linear)
local confirmButtonTweenReverse = TweenService:Create(confirm, confirmButtonInfoReverse, {BackgroundColor3 = Color3.fromRGB(30, 255, 120)})
if errorGui.Background.Position == targetPosition then
local repeatInfo = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out,0,true)
local errorColorTween = TweenService:Create(errorMessage, repeatInfo, {TextColor3 = errorColor})
errorColorTween:Play()
end
errorMessage.Text = message
errorGui.Enabled = true
errorTween:Play()
confirmButtonTween:Play()
local waitTime = 6
for i = 6, 0, -0.1 do
confirm.Text = math.round(waitTime*10)/10
waitTime -= 0.1
task.wait(0.1)
end
errorTweenReverse:Play()
errorGui.Enabled = false
errorMessage.Text = ""
confirmButtonTweenReverse:Play()
confirm.Text = "Confirm"
confirmDebounce = false
end
Do you see what I mean? It’s a complete mess. It’s so time consuming and makes editing the code so inconvenient and inefficient. If anyone has any ideas/advice, I’d love to hear it!
Side note: I also never know how to set up the Goals = {} part of the tween. It seems as though every instance needs its own unique way of writing it.
Examples:
BackgroundColor3 = Color3.fromRGB(0,0,0)
Color3 = Color3.new(0,0,0)
Brickcolor = Brickcolor.new(“really red”)
Position = …
CFrame = …
Size = …
etc.
I’ve used tweens countless times but can’t seem to memorize each one so I often spend a ton of time sifting through various DevForum posts trying to figure out which one to use for my specific case. Like why are there 3 different methods for changing the color? It’s just confusing to me.