So when a player kills another player. I want to have a +50 points pop up. I need this to scale from 0 to x size within 1 second, and then a second later tween back to 0.
I can do this via a tween and when the tween completes have another tween scale it back down to 0.
But if the player kills multiple players within a few seconds (even though the tween should make it tween back to x size, it might run the other tween and scale the text to 0. If this makes sense?
How can I no matter what reset the tween and scale from it’s current size to the goal size I need, and then if no other players are killed in the duration, tween it back down uninterrupted?
If two tweens attempt to change the same property of the same instance, the first will be cancelled, and only the second run.
If you wanted to make sure you could also store the tween in a variable outside the function which creates it, and disconnect the tween finished event.
Something like this:
local tween
local tweenFinishedConn
local function tweener()
if tween then
tween:Cancel()
end
if tweenFinishedConn then
tweenFinishedConn:Disconnect()
end
tween = --create the tween to size to x
tweenFinishedConn = tween.Finished: Connect(function ()
--run resize to 0 tween
tween = nil
tweenFinishedConn:Disconnect()
tweenFinishedConn = nil
end)
tween:Play()
end
tweener()