DamageIndicators - Open Source Damage UI!

DamageIndicators - Free, Customizable, and Easy to Implement

8b43f564048784bceb5e01aaf593d156

I’m not a UI designer, so you can customize the look of your indicators to fit your exact needs! The size of the text also is relative to the amount of damage taken!

Implementation
DamageIndicators is a class with 2 primary methods of implementation. The first is direct, while the other will bind to ALL NPCs in your game. In order for the class to work, the NPC must have a head and humanoid.

Direct

DamageIndicator.new(workspace.CheekySquid)

This will bind to the NPC you have indicated. When the NPC dies or is removed, it automatically unbinds itself.

Universal

DamageIndicator.BindToAllNPCs()

This will bind to all NPCs found in the game.

Take it here!
DamageIndicators - Open Source UI Damage System

Be sure to leave any feedback and criticism. I will work to maintain this module and potentially add a better-looking indicator UI. Enjoy!

72 Likes

Very cool and useful plugin thanks for sharing! I will definitely give this a try.

3 Likes

Thanks for making this! will use this later on

3 Likes

Thanks for sharing, will come in handy. :sunglasses:

Look at that handsome noob loosing and gaining health with indication. But in all seriousness, thanks for making this. This is a very useful resource! :100:

2 Likes

You should add presents for this module instead of just text tweening up.

I do not understand how to use this, I placed it in a Rep Storage Directory, what else?

( I am very bad with modulescripts )

This doesn’t seem to work on players, Is this intentional? Other than that this is a good module to use

Cool im gonna use it also thanks!

Nice job, I’m defo adding this to my game. Keep up the good work broski

How do you make it work with players?

This works very well, the only problem that it doesnt work with clones? Tried everything but it just doesnt work.

1 Like

Works perfectly, thank you :+1:

where d y put in on is it on workspace or where

Remade it so it works for players and npcs only did npcs 2 since i got nun in my game

-- Damage Indicator
-- CheekySquid // Made live on Twitch! // CheekyVisuals on Twitch
-- 2/7/2020

--[[
    Methods:
        public metatable new(instance)
    
        public void Bind(instance)
        public void Destroy()
        public void SpawnUI(number amount)
        public Color3 GetIndicatorColor(number amount)
        
        public static void BindToAllCharacters()
        
    Attributes:
        public number currentHealth
        public instance humanoid
        public instance head
        public instance
        
        private metatable _maid
        
    Usage Examples:
        DamageIndication.new(workspace.CheekySquid)
        DamageIndication.BindToAllCharacters()
--]]

--// Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

--// Modules
local Maid = require(script.Maid)

--// Assets
local uiTemplate = script.DamageTemplate

--// Objects
local random = Random.new()

local DamageIndication = {}
DamageIndication.__index = DamageIndication

function DamageIndication.new(instance)
    local self = setmetatable({}, DamageIndication)
    
    self._humanoid = instance:FindFirstChildWhichIsA("Humanoid")
    self._head = instance:FindFirstChild("Head")
    self._instance = instance
    
    self._maid = Maid.new()
    
    self:Bind()
    
    return self
end


function DamageIndication:Bind()
    assert(self._humanoid, "Instance does not contain a humanoid")
    assert(self._head, "Instance does not contain a head part")
    
    self.currentHealth = self._humanoid.Health
    
    self._maid:GiveTask(self._humanoid.HealthChanged:Connect(function(newHealth)
        if newHealth < self.currentHealth then
            local damage = self.currentHealth - newHealth
            self.currentHealth = newHealth
            self:SpawnUI(damage)
        else
            self.currentHealth = newHealth
        end
    end))
    
    self._maid:GiveTask(self._instance.AncestryChanged:Connect(function()
        if not self._instance:IsDescendantOf(game) then
            self:Destroy()
        end
    end))
    
    self._maid:GiveTask(self._humanoid.Died:Connect(function()
        self:Destroy()
    end))
end

function DamageIndication:SpawnUI(amount)
    local indicator = uiTemplate:Clone()
    local label = indicator.Label
    
    label.Text = tostring(math.floor(math.abs(amount)))
    label.TextColor3 = self:GetIndicatorColor(amount)
    
    -- Position the indicator above the head
    local attachment = Instance.new("Attachment")
    attachment.Position = Vector3.new(0, 3, 0)  -- Adjust this offset as necessary
    attachment.Parent = self._head
    
    indicator.Adornee = attachment
    indicator.Parent = game.Workspace
    
    -- Tween the indicator upwards and fade out
    local tweenPosition = TweenService:Create(indicator, TweenInfo.new(1, Enum.EasingStyle.Linear), {
        StudsOffset = Vector3.new(0, 2, 0)  -- Adjust this offset as necessary
    })
    
    local tweenTransparency = TweenService:Create(label, TweenInfo.new(1, Enum.EasingStyle.Linear), {
        TextTransparency = 1,
        TextStrokeTransparency = 1
    })
    
    tweenPosition:Play()
    tweenTransparency:Play()
    
    tweenTransparency.Completed:Connect(function()
        indicator:Destroy()
        attachment:Destroy()
    end)
end

function DamageIndication:GetIndicatorColor(amount)
    return Color3.fromRGB(255, 0, 0)
end

function DamageIndication:Destroy()
    self._maid:Destroy()
end


function DamageIndication.BindToAllCharacters()
   
    for _, instance in ipairs(workspace:GetDescendants()) do
        if instance:IsA("Model") and instance:FindFirstChildWhichIsA("Humanoid") and instance:FindFirstChild("Head") then
            DamageIndication.new(instance)
        end
    end

    
    workspace.ChildAdded:Connect(function(child)
        if child:IsA("Model") and child:FindFirstChildWhichIsA("Humanoid") and child:FindFirstChild("Head") then
            DamageIndication.new(child)
        end
    end)

    
    for _, player in ipairs(Players:GetPlayers()) do
        if player.Character then
            DamageIndication.new(player.Character)
        end
        player.CharacterAdded:Connect(function(character)
            DamageIndication.new(character)
        end)
    end

 
    Players.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
            DamageIndication.new(character)
        end)
    end)
end

return DamageIndication

Script: DamageIndication.BindToAllCharacters()

does this work on the player too?