Better damage indicator LIKE GPO

I made a damage indicator local script like studio, it can work in server script and local script

If anyone wants to change from local script to server script, it is possible, the reason why I made local script is because it only shows 1 player

Script: https://www.roblox.com/library/9934898877/DamageIndicator
PREVIEW:

If there are any errors, please report them to me! Thanks very much!

Update Log

  • Fixed Character Added Not Get The Damage Indicator.

If there are any errors, please report them to me! Thanks very much!

31 Likes

Add images or other medias please

10 Likes

here
robloxapp-20220616-0723185.wmv (1.3 MB)

NEW UPDATE : DamageIndicator - Roblox

2 Likes

Don’t use the built-in Recorder for previewing showcase, use another one like OBS or Xbox Game recorder instead.

wmv isn’t accessible through smartphones

1 Like

Please use another more modern format like .mp4

1 Like

This is epic, I’m definitely going to use this for my devilfruits, could you also make a gpo like hit counter?

1 Like

HERE:

Theres an issue with this script,
One issue is that when new characters are added to the workspace they don’t get the damage indicator.
Fixed version below:

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,-1,true,0)

local function Scan(Model)
	if Model.ClassName == "Model" and Model:FindFirstChild("Humanoid")  then
		local OHumanoid = Model.Humanoid
		local OHumrp = Model.HumanoidRootPart
		local currentHealth = OHumanoid.Health
		OHumanoid.HealthChanged:Connect(function(health)
			
			local damage = math.abs(currentHealth - health)
			local DMGLabel = script.DamageLabel:Clone()
			game.Debris:AddItem(DMGLabel,.5)
			DMGLabel.BillboardGui.TheShadow.Text = math.floor(damage)
			DMGLabel.BillboardGui.Shadow.Text = DMGLabel.BillboardGui.TheShadow.Text
			TS:Create(DMGLabel.BillboardGui.TheShadow,TI,{TextColor3 = Color3.new(1, 1, 1)}):Play()
			DMGLabel.Position = OHumrp.Position
			DMGLabel.Parent = workspace
			DMGLabel.Velocity = Vector3.new(math.random(-20,20),math.random(20,25),math.random(-20,20))
			currentHealth = health
		end)
	end
end

for _, Model in pairs(workspace:GetDescendants()) do
	Scan(Model)
end

workspace.DescendantAdded:Connect(function(Object)
	Scan(Object)
end)
1 Like
for _, Model in pairs(workspace:GetDescendants()) do
	Scan(Model)
end

it will create an infinite loop

You need this, your fixed version does not works

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,-1,true,0)

local function Scan(Model)
	if Model.ClassName == "Humanoid" then
		local OHumanoid = Model
		local OHumrp = OHumanoid.Parent.HumanoidRootPart
		local currentHealth = OHumanoid.Health
		OHumanoid.HealthChanged:Connect(function(health)
			local damage = math.abs(currentHealth - health)
			local DMGLabel = script.DamageLabel:Clone()
			game.Debris:AddItem(DMGLabel,.5)
			DMGLabel.BillboardGui.TheShadow.Text = math.floor(damage)
			DMGLabel.BillboardGui.Shadow.Text = DMGLabel.BillboardGui.TheShadow.Text
			TS:Create(DMGLabel.BillboardGui.TheShadow,TI,{TextColor3 = Color3.new(1, 1, 1)}):Play()
			DMGLabel.Position = OHumrp.Position
			DMGLabel.Parent = workspace
			DMGLabel.Velocity = Vector3.new(math.random(-20,20),math.random(20,25),math.random(-20,20))
			currentHealth = health
		end)
	end
end

for _, Model in pairs(workspace:GetDescendants()) do
	Scan(Model)
end
workspace.DescendantAdded:Connect(function(Object)
	Scan(Object)
end)

How does this create a infinite loop

1 Like

It will find model but if model not have a humanoid then it will find it again, i know you do it by player joined the game then the damage indicator will active. This situation will cause the game to lag, and I don’t have a solution to prevent this yet.

I think you’re misunderstanding something here, the code doesn’t produce an infinite loop it iterates through all the objects in workspace one by one one checking if they’re

  1. a model
  2. a parent to a humanoid
    if its a model with a humanoid inside of it then it’ll run the code there isn’t a infinite loop to be had here however it is better to check if the object is a humanoid instead of checking if its a model with a humanoid inside of it
1 Like

Thanks for pointing out my mistake! but if you want the script to work change the “and” in “if Model.ClassName == “Model” and Model:FindFirstChild(“Humanoid”) then” to “or” or can leave out the “Model.ClassName ==” “Model”, it will be much more compact and easier!

And I also created the most complete fix–

*Thank you so much for contributing so much to this system!

:spiral_notepad: GOOD RESOURCE

Hey, the script is awesome! It’s a cool resource I must say, no hesitation here. I have always liked damage indicators in games, they sure are a nice addition and it provide such information towards the user, and gives it a nice touch to it.

Although, there are some tips you could do to improve the code for better usage of others that are using this resource!


:bulb: HELPFUL TIPS

  • Here are some tips that I know of that can definitely help to improve the resource. You may apply these changes to your liking, it’s yours afterall.

1. Use Instance:IsA)

  • Don’t blame me on this one as it is up to your preferences. Using Model.ClassName == "Model" works too, but in my opinion, using IsA() is way better and looks cleaner in my experience of using. It is highly recommend you use this over ClassName.
if Model:IsA("Model") then

This should do the trick! I’m not that confident of myself, so any mistakes being thrown here is my apologies due to my lack of knowledge.


2. Use Instance:FindFirstChildOfClass()

  • Now, you may be wondering, why use this over FindFirstChild()? Well, you see, Humanoid is a class, and using FindFirstChild() only find an instance that is named Humanoid (recursive too, but blayt), and not it’s class type. Your module utilizes Humanoid’s elements and it is needed in the first place.

Let’s say this: "You have an NPC, and the humanoid is named Zombie. Now, using FindFirstChild() will not result in anything as it is not able to find an instance with the name Humanoid within the NPC’s children, therefore the effect of the indicator will be ignored for that NPC. So, using FindFirstChildOfClass() will override and fix the problem. No matter what you name the humanoid, it will always count as the class is Humanoid.

Instance:FindFirstChildOfClass("Humanoid")
local humanoid = Instance:FindFirstChildOfClass("Humanoid")

3. Rearrange Variables/Services

  • One of many common problems in scripting is how the scripter choose to name their variables. They are an important aspect of scripting and will always be. You will always need to use a variable the very least when it comes to scripting. And so, don’t be lazy! Treat your variables nice and well if you have the time for it. If you did it correctly, your script should be more organized than ever.
---------- [ SERVICES ] ----------
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")

---------- [ VARIABLES ] ----------
-- You can name it anything as long as it doesn't confuse you.

local damage_label = script:FindFirstChild("DamageLabel")
local tweenInfo = TweenInfo.new(
     0.5,
     Enum.EasingStyle.Linear,
     Enum.EasingDirection.InOut,
     -1,
     true,
     0
)

---------- [ FUNCTIONS ] ----------
local function Scan(model)
     . . .
     -- check if NPC aka model have humanoid or not
     -- if not, return and stop the function from running anymore.

     -- do the damage indicator, etc
     -- clone the indicator (damage_indicator variable) and create a tween for it
end

---------- [ CONNECTIONS ] ----------
for _, instance in ipairs(workspace:GetDescendants()) do
     if instance:IsA("Model") then
          Scan(instance)
     end
end

workspace.DescendantAdded:Connect(function(descendant)
     if descendant:IsA("Model") then
          Scan(descendant)
     end
end

:pushpin: CONCLUSION

  • Overall, this is an amazing resource. It will be sure to help those who are in need of damage indicator. Though, you could turn it into a Module Script instead, but that is a different approach. You’ve still got tons to learn, and you give it your very best. Be proud of what you have accomplished, and keep moving onward!

Also, what @binky007 said is true.
Anyways, wrote all of this on mobile. It was a struggle, but sure was worth it. Any mistakes, I sincerely apologize as I was only trying to point out the obvious that the original code had and can be improved. Cheers, everyone! :happy2:

P.S: I might add more tips when I get back to my PC, but we’ll see. I’m kind of pushed for now, haha!

4 Likes

nice tips! thanks so much! ︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎︎ ︎
︎ ︎

can u update the model its not working anymore?

Dam, i need that damage indicator animation text ;-;, but sadly the account is gone

is someone able to send me the model for this? the link isnt working