I have been extremely modifying a gun script and the last thing that I have to change is so when a bullet hits a players accessory it still damages them.
But at the moment it doesnt so, lets say a player has a backpack on. If they get hit in the backpack nothing happens.
Heres the code, these are just 2 chunks of the code, but its the part that does the damage.
LOCAL SCRIPT
if not Module.ExplosiveEnabled then
if Hit and Hit.Parent then
local TargetHumanoid = Hit.Parent:FindFirstChild("Humanoid")
local TargetTorso = Hit.Parent:FindFirstChild("UpperTorso")
local TargetAddon = Hit.Parent:FindFirstChildOfClass("Accessory")
--local TargetTEAM = Hit.Parent:FindFirstChild("TEAM")
if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso and TargetAddon then
--if TargetTEAM and TargetTEAM.Value ~= TEAM.Value then
InflictTarget:FireServer(TargetHumanoid,
TargetTorso,
TargetAddon,
(Hit.Name == "Head" or Hit.Name == "Helmet" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage,
Direction,
Module.Knockback,
Module.Lifesteal,
Module.FlamingBullet)
PiercedHumanoid[TargetHumanoid] = true
--end
else
PierceAvailable = 0
end
end
else
SERVER SCRIPT
InflictTarget.OnServerEvent:connect(function(Player,TargetHumanoid,TargetTorso,TargetAddon,Damage,Direction,Knockback,Lifesteal,FlamingBullet)
if Player and TargetHumanoid and TargetHumanoid.Health ~= 0 and TargetTorso and TargetAddon then
while TargetHumanoid:FindFirstChild("creator") do
TargetHumanoid.creator:Destroy()
end
local creator = Instance.new("ObjectValue",TargetHumanoid)
creator.Name = "creator"
creator.Value = Player
game.Debris:AddItem(creator,5)
TargetHumanoid:TakeDamage(Damage)
if Knockback > 0 then
TargetTorso.Velocity = Direction * Knockback
end
if Lifesteal > 0 and Humanoid and Humanoid.Health ~= 0 then
Humanoid.Health = Humanoid.Health + (Damage*Lifesteal)
end
if FlamingBullet then
local Debuff = TargetHumanoid.Parent:FindFirstChild("IgniteScript") or script.IgniteScript:Clone()
Debuff.creator.Value = Player
Debuff.Disabled = false
Debuff.Parent = TargetHumanoid.Parent
end
end
end)
Youll notice ive modified it myself or attempted at it, I added TargetAddon to both of the scripts but that doesnt do anything.
Thank you for your time, hopefully some one may figure this out.
Allow me to add the fact that the accessory is made of parts, not a mesh. The gun script works with accessories that are made of meshes but not ones that are made of parts.

4 comments
But its hitting a part inside an accessory. So the parent of the part is the accessory.
Plus isnt that what my script is already doing??
Try making it check if hit.Parent is an accessory, if it is then it searches the parent of the accessory
It works when the accessory is made of meshes but when its made of parts it doesnt work.