Multiple Tween animation interrupt each other

So I currently have a working kill indicator GUI for players with tween transparent animations, basically when you kill a player a text label pops up saying “killed {name}” for 3 seconds, but the only issue is that whenever I kill more than one person within 3 seconds, the first tween’s transparency animation overrides the 2nd tween’s animations, making it appear for less time. How can I fix this so that the tween animations wont interrupt each other?

-- // Services

-- External services
local tweenService = game:GetService("TweenService")

-- Default services
local replicatedStorage = game:GetService("ReplicatedStorage")
local playersService = game:GetService("Players")

-- // Variables

-- Comms variables
local killEvent = replicatedStorage:WaitForChild("KillNotification")

-- Player variables
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

-- UI variables
local killGUI = script.Parent
local notification = killGUI:WaitForChild("Notification")

local killSound = script:WaitForChild("KillSound")

-- // Functions

local function tweenTransparency(guiObject, duration, transparency, Override)
    spawn(function()
        
        local tween = nil
        
        if guiObject:IsA("TextLabel") then
            local tween = tweenService:Create(guiObject, TweenInfo.new(duration), {TextTransparency = transparency}, {Override = Override})
            
            tween:Play()

            spawn(function()
                tween.Completed:Wait()
                tween:Destroy()
            end)
        elseif guiObject:IsA("ImageLabel") then
            local tween = tweenService:Create(guiObject, TweenInfo.new(duration), {ImageTransparency = transparency}, {Override = Override})
            
            tween:Play()

            spawn(function()
                tween.Completed:Wait()
                tween:Destroy()
            end)
        end
        
        if tween ~= nil then
            return tween
        end
        
    end)
end

local function notify(victim)

	notification.TextTransparency = 1
    
    notification.Text = "<font color='#ff3a3a'>Eliminated: </font>" .. victim.Name
    
	killSound:Play()
	tweenTransparency(notification, 0.5, 0, true)
	notification:TweenSize(UDim2.new(0.302, 0, 0.052, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
	wait(0.1)
	notification:TweenSize(UDim2.new(0.216, 0, 0.037, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
	wait(3)
	tweenTransparency(notification, 0.5, 1, true)
	
end

-- // Connection

How I would do it is:
First off I would make a variable named “activeTextLabel”, this will be a bool variable, and will be true whenever there is a textLabel is already on screen, and false when there isn’t.
Wherever the script starts to add the next text function is where you could add something similar to:

if activeTextLabel then
repeat
wait(.01)
until not activeTextLabel
end

And then hopefully that should solve your problem.

1 Like

So I added a bool value to the script to determine whether or not the text label is active and it fixed my issue, Thanks A lot!

1 Like