Hello Developers! I need help with a script which shows the amount of damage when attacking an NPC. However although it dosent do damage to players it still shows numbers on top of the players head which means it says damage is being done even though their health bar doesn’t go down on either screen. So how can I make it that it only shows the numbers of damage when you are attacking NPC’s and not for players, because in my game you cant attack players. Here is my script which triggers the damage indicator:
if IsServer then
if target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if dealerHumanoid and target ~= dealerHumanoid and targetPlayer and game.Players:GetPlayerFromCharacter(dealer.Parent) then
-- Trigger the damage indicator
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
end
end
Please modify it so it only shows when attacking NPC’s and not players!
I have the script right there it activates when the bullet has touched a object containing a humanoid. I want it to check if the object is a NPC or player.
if IsServer then
if target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if dealerHumanoid and target ~= dealerHumanoid and targetPlayer and game.Players:GetPlayerFromCharacter(dealer.Parent) then
-- Trigger the damage indicator
if game:GetService("Players"):FindFirstChild(target.Parent.Name) then
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
else
print("is no player")
end
end
end
If you have the humanoid set as the variable target then do this:
local target = -- the humanoid
local player = game:GetService("Players"):GetPlayerFromCharacter(target.Parent)
if player then
-- code for the player
else
-- code for the NPC
end
You can add a value inside the npc and name it something like npc and give it a true and then in the script check if targetYouHit:FindFirstChild(“IsNpc”) ~= nil then