Help with > Damage indicator for enemy

Hello, I would like to know how I can make a damage indicator for the enemy, because I already tried and so far I couldn’t.

Or even if better, how do I fix the GUIDamage of the code below, just above the enemy’s head?

GUIDamage:

local SizeOni = UDim2.new(0,200 , 0,50)

-- Script abaixo da TakeDamage			
local GUIDamage = Instance.new("Part")	
GUIDamage.Parent = workspace
GUIDamage.Name = "GUIDamage"
GUIDamage.Anchored = true
GUIDamage.Transparency = 1
GUIDamage.CanCollide = false
GUIDamage.CFrame = hit.Parent.HumanoidRootPart.CFrame * CFrame.new(math.random(-3,3),math.random(-1,1),math.random(-3,3))
local GUIDamage2 = Instance.new("BillboardGui")
GUIDamage2.Parent = GUIDamage
local GUIDamage3 = Instance.new("TextLabel")
GUIDamage3.Font = "FredokaOne"
GUIDamage3.Parent = GUIDamage2
GUIDamage3.BackgroundTransparency = 1
GUIDamage3.TextScaled = true
GUIDamage3.TextStrokeTransparency = 0
GUIDamage3.TextColor3 = Color3.fromRGB(222, 8, 12)
GUIDamage3.Text = "-"..Damage
GUIDamage2.Size = SizeOni
GUIDamage3.Size = SizeOni

you will need to make a separate server script and put this code in if that doesn’t work then ill show you something else

local tweenService = game:GetService("TweenService")
 
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
 
local damageForColours = 
{
  --You can change this to any color you want!
    [25] = Color3.fromRGB(255, 196, 101),
    [50] = Color3.fromRGB(255, 234, 0),
    [75] = Color3.fromRGB(255, 140, 0),
    [100] = Color3.fromRGB(255, 0, 0),
}
 
game.Players.PlayerAdded:Connect(function(plr)
    
    plr.CharacterAdded:Connect(function(char)
        
        local humanoid = char:WaitForChild("Humanoid")
        local currentHealth = humanoid.Health
        
        humanoid.HealthChanged:Connect(function(health)
            
            if health < currentHealth and humanoid:GetState() ~= Enum.HumanoidStateType.Dead then
            
                local healthLost = math.floor(currentHealth - health)
                
                
                local damageIndicatorGui = Instance.new("BillboardGui")
                damageIndicatorGui.AlwaysOnTop = true
                
                damageIndicatorGui.Size = UDim2.new(1.5, 0, 1.5, 0)
                
                local offsetX = math.random(-10, 10)/10
                local offsetY = math.random(-10, 10)/10
                local offsetZ = math.random(-10, 10)/10
                damageIndicatorGui.StudsOffset = Vector3.new(offsetX, offsetY, offsetZ)
                
                local damageIndicatorLabel = Instance.new("TextLabel")
                
                damageIndicatorLabel.AnchorPoint = Vector2.new(0.5, 0.5)
                damageIndicatorLabel.Position = UDim2.new(0.5, 0, 0.5, 0)
                
                damageIndicatorLabel.TextScaled = true
                damageIndicatorLabel.BackgroundTransparency = 1
                damageIndicatorLabel.Font = Enum.Font.GothamBlack
                
                damageIndicatorLabel.Text = healthLost
                
                damageIndicatorLabel.Size = UDim2.new(0, 0, 0, 0)
                
                for damage, colour in pairs(damageForColours) do
                    
                    if healthLost <= damage then 
                        
                        damageIndicatorLabel.TextColor3 = colour
                        damage = 100
                    end
                end
                
                damageIndicatorLabel.Parent = damageIndicatorGui
                
                damageIndicatorGui.Parent = char.HumanoidRootPart
                
                damageIndicatorLabel:TweenSize(UDim2.new(1, 0, 1, 0), "InOut", "Quint", 0.3)
                
                
                wait(0.3)
                
                local guiUpTween = tweenService:Create(damageIndicatorGui, tweenInfo, {StudsOffset = damageIndicatorGui.StudsOffset + Vector3.new(0, 1, 0)})
                
                local textFadeTween = tweenService:Create(damageIndicatorLabel, tweenInfo, {TextTransparency = 1})
                
                guiUpTween:Play()
                textFadeTween:Play()
                
                game:GetService("Debris"):AddItem(damageIndicatorGui, 0.3)
            end
            
            currentHealth = humanoid.Health
        end)
    end)
end)

I use this script in the player, but for the enemy it doesn’t work, I’m making a script here and it seems to be working.

More thanks for your attention.

My script should hit a humanoid does your monster have a humanoid?

Oh srry your trying to put a GUI over the enemy head so hold on

I did the following, and no error occurred, it came out just right.

function damageIndicator(hit, Humanoid, damage)
	local GUIDamage = Instance.new("Part")	
	GUIDamage.Parent = workspace
	GUIDamage.Name = "GUIDamage"
	GUIDamage.Anchored = true
	GUIDamage.Transparency = 1
	GUIDamage.CanCollide = false
	GUIDamage.CFrame = hit.Parent.HumanoidRootPart.CFrame * CFrame.new(math.random(-3,3),math.random(-1,1),math.random(-3,3))
	local GUIDamage2 = Instance.new("BillboardGui", Humanoid.Parent.Head)
	GUIDamage2.Parent = GUIDamage
	GUIDamage2.AlwaysOnTop = true
	local GUIDamage3 = Instance.new("TextLabel", GUIDamage2)
	GUIDamage3.Font = "FredokaOne"
	GUIDamage3.Parent = GUIDamage2
	GUIDamage3.BackgroundTransparency = 1
	GUIDamage3.TextScaled = false
	GUIDamage3.TextStrokeTransparency = 0
	GUIDamage3.TextColor3 = Color3.fromRGB(199, 199, 0)
	GUIDamage3.TextSize = 17
	GUIDamage3.Text = "-"..math.floor(damage)
	GUIDamage2.Size = UDim2.new(0, 50, 0, 100) 
	GUIDamage3.Size = UDim2.new(0, 50, 0, 100) 
	wait(0.4)
	GUIDamage:Destroy()
	GUIDamage2:Destroy()
	GUIDamage3:Destroy()
end

And below the TakeDamage I insert

Ex: damageIndicator(hit, Humanoid, 10)

so i did help you or not I’m confused

1 Like

It helped, you can rest assured.

okay glad i helped, is there any issues at all with it before I bounce?

1 Like

None, thank you very much, hey do you have any contact as I would like some help with the game if you want

Okay yeah sure ill send a message

1 Like

@rafarp23 i sent you the message if you ever want to contact