I made stackable Damage indicators, they are almost working, the only problem is that when I hit 2 humanoids it creates only 1 indicator instead of 2, how can I get separate indicators for different humanoids?
My Code:
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local tweenInf = TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,-1,true,0)
currentgui = nil
num = 0
local function makegui(damage, person, bool)
if bool == false then
DMGLabel = rs.DamageIndicator.DamageLabel:Clone()
DMGLabel.BillboardGui.TheShadow.Text = math.floor(damage)
DMGLabel.BillboardGui.TheShadow.TextColor3 = Color3.new(1, 0.0941176, 0.0941176)
ts:Create(DMGLabel.BillboardGui.TheShadow,tweenInf,{TextColor3 = Color3.new(1, 1, 1)}):Play()
DMGLabel.Position = person.HumanoidRootPart.Position
DMGLabel.Parent = workspace.DebrisFolder
DMGLabel.Velocity = Vector3.new(0,30,0)
local oldText = DMGLabel.BillboardGui.TheShadow.Text
task.delay(1.5,function()
local newText = DMGLabel.BillboardGui.TheShadow.Text
if oldText == newText then
currentgui = false
DMGLabel:Destroy()
end
end)
end
if bool == true then
DMGLabel.BillboardGui.TheShadow.TextColor3 = Color3.new(1, 0.0941176, 0.0941176)
ts:Create(DMGLabel.BillboardGui.TheShadow,tweenInf,{TextColor3 = Color3.new(1, 1, 1)}):Play()
DMGLabel.Position = person.HumanoidRootPart.Position
DMGLabel.BillboardGui.TheShadow.Text += damage
local oldText = DMGLabel.BillboardGui.TheShadow.Text
task.delay(1.5,function()
local newText = DMGLabel.BillboardGui.TheShadow.Text
if oldText == newText then
currentgui = false
DMGLabel:Destroy()
end
end)
end
end
function showdamage(damage, person)
if not currentgui then
currentgui = true
makegui(damage, person, false)
else
makegui(damage, person, true)
end
end
local function Scan(Model)
if Model.ClassName == "Humanoid" then
local OHumanoid = Model
local OHumrp = OHumanoid.Parent:WaitForChild("HumanoidRootPart")
local eChar = OHumrp.Parent
local currentHealth = OHumanoid.Health
OHumanoid.HealthChanged:Connect(function(health)
if health < currentHealth then
local damage = math.abs(currentHealth - health)
showdamage(damage,eChar)
currentHealth = health
elseif health > currentHealth then return
end
end)
end
end
for _, Model in pairs(workspace:GetDescendants()) do
Scan(Model)
end
workspace.DescendantAdded:Connect(function(Object)
Scan(Object)
end)