Hey i was making a damage indicator, and it was working fluently for the first time, when you hit an enemy it shows how much damage you’ve dealt to him. And the numbers indicating the damage dissapear after like a second. But for some odd reason when i hit him for the second time, it still does the same damage as normal, but there is +1 Gui, like the last one didn’t delete or something. But in the workspace it does get deleted, so you get alot of many other questions
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
function damageIndicator(EnemyHumanoid)
local currentHealth = EnemyHumanoid.Health
EnemyHumanoid.HealthChanged:Connect(function(health)
if health < currentHealth and EnemyHumanoid:GetState() ~= Enum.HumanoidStateType.Dead then
local healthLost = 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 = EnemyHumanoid.Parent.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 = EnemyHumanoid.Health
end)
end