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!
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
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!
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!