I am making a UI for when a player picks up some cash a little notification in the bottom right of the screen pops up telling them how much money they picked up. It will then transition up and fade out until it is fully transparent ready to be used again. Pretty simple right? Well, I want to now make it when a player picks up some cash right after picking up other cash it will then immediately teleport the notification label back to the start of the transition and add the previous cash picked up value to the new cash picked up value and then continue with transitions, etc. I have attempted this twice but can’t seem to figure it out I had the idea of using promises to try and accomplish this but couldn’t figure out the logic if anyone knows how I could do this or accomplish this. That would be really appreciated thanks so much in advance!
Set up a total outside the function starting at 0 which represents the amount they have picked up in this streak.
Then create a function that handles animation when adding new funds
Create a temporary value to hold the current total plus the new funds
Update total to equal the temp value (for later comparison)
Reset the position, color, transparency etc of the guis you intend to animate
Start their tweens
Wait until tween end
If total is the same as temp value (meaning no new money was added since tween start) reset total to 0. Otherwise do nothing
That’s essentially the logic here
Here is a coded example
local TweenService = game:GetService("TweenService")
local animTweenInfo = TweenInfo.new(2)
local total = 0
local function startAnimation(addedCash)
--Setup value for comparison
local startCash = total + addedCash
total = startCash
--reset gui to tween start
script.Parent.Animated.Position = UDim2.fromScale(1,1)
script.Parent.Animated.BackgroundTransparency = 0.25
script.Parent.Animated.TextLabel.TextTransparency = 0
script.Parent.Animated.TextLabel.Text = "+" .. tostring(total)
--Create tweens
local parentTween = TweenService:Create(script.Parent.Animated, animTweenInfo, {
Position = UDim2.new(1,0,1,-200),
BackgroundTransparency = 1
})
local subTween = TweenService:Create(script.Parent.Animated.TextLabel, animTweenInfo, {
TextTransparency = 1
})
parentTween:Play()
subTween:Play()
--Wait until tweens done (end combo)
parentTween.Completed:Wait()
if total == startCash then --Check that the function hasn't run again adding more money
total = 0 --If this is the last addition, end the combo by resetting total
end
end