Made this years ago. I thought I would share it. Its very basic and simple to use and implement into pre-existing games.
Note if you’re going to use the rbxm please set the text of the text label to 0 if you do not want the displayed value to be preset to a base value which will be added too.
Example: base = 100; base + 10 = 110
All you need to do is add the two remotes inside of the code and place them and move the billboard gui into replicated storage and the local script into starterplayerscripts.
It also comes with support for kill/hit sounds but you can comment that separate code out if you just want to use the indicator.
If you want to do a timed destroy system that utilises tick then just copy the below code into your script:
DmgIndi.OnClientEvent:Connect(function(damage, target)
local s = tick()
local DamageNumber = nil
--Check if there's already a damage number
DamageNumber = target.Parent.Head:FindFirstChild('DamageNumber')
if DamageNumber == nil then
--There isn't one, make one now
DamageNumber = game:GetService('ReplicatedStorage').DamageNumber:Clone()
else
--There is one, add to it
damage += tonumber(DamageNumber.TextLabel.Text)
end
DamageNumber.Parent = target.Parent.Head
DamageNumber.TextLabel.Text = tostring(damage)
repeat task.wait() until tick() - s >= 5
print(tick() - s >= 5)
DamageNumber:Destroy()
end)
No problem. I did have a version that had a couple tweens and stuff to make the number popup and fade randomly in a random direction on the z or x axis but I lost it since I didn’t backup my old game before leaving my old group which got sniped.
For a little more insight it would’ve looked similar to Fortnite’s damage indicator.
I would’ve posted that one here instead but I thought I may aswell upload this base for anyone else to enjoy.
I have now added two tweens to have the number fade in and out and should also pop in and out a little bit.
Add the following code:
local TweenService = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
DmgIndi.OnClientEvent:Connect(function(damage, target)
local s = tick()
local DamageNumber = nil
--Check if there's already a damage number
DamageNumber = target.Parent.Head:FindFirstChild('DamageNumber')
if DamageNumber == nil then
--There isn't one, make one now
DamageNumber = game:GetService('ReplicatedStorage').DamageNumber:Clone()
end
-- this is really the only good way to get a number between the two values.
local min, max = -0.2, 0.2
local rnd = Random.new():NextNumber(min, max)
local tween = TweenService:Create(DamageNumber.TextLabel, tweeninfo,
{
Position = UDim2.new(rnd, 0, -0.3, 0),
TextSize = 65,
TextTransparency = 0.3
}
)
local tween2 = TweenService:Create(DamageNumber.TextLabel, tweeninfo,
{
Position = UDim2.new(0, 0, 0, 0),
TextSize = 50,
TextTransparency = 1
}
)
tween:Play()
tween.Completed:Once(function()
tween2:Play()
end)
-- wait until the tweens are both completed, no connection needed as we can check at any point if it is completed
repeat task.wait() until tween2.Completed and tween.Completed
--There is one, add to it
damage += tonumber(DamageNumber.TextLabel.Text)
DamageNumber.Parent = target.Parent.Head
DamageNumber.TextLabel.Text = tostring(damage)
repeat task.wait() until tick() - s >= 5
DamageNumber:Destroy()
end)
You will need to change the property from the label to the following in the screenshot unless you’re going to edit the script