Accessory isn't detected

local Module = {}
-- Library
Module.Tool = script.Parent
Module.Settings = require(Module.Tool.Settings)
Module.Handle = Module.Tool.Handle
Module.Form = Module.Tool.Form
Module.ReserveGUI = Module.Tool.GunGUI
Module.GUI = nil

Module.CurrentAmmo = Module.Settings.AmmoPerClip
Module.CurrentClips = Module.Settings.Clips
Module.ArmsDown = false

function Module:TagHumanoid(Player,Humanoid,Dmg)
	if Humanoid:FindFirstChild(Player.Name) then
		local C = Humanoid:FindFirstChild(Player.Name)
		if C.Value + Dmg < Humanoid.MaxHealth then
			C.Value = C.Value + Dmg
		else
			C.Value = Humanoid.MaxHealth
		end
	else
		local C = Instance.new("NumberValue",Humanoid)
		C.Name = Player.Name
		if Dmg < Humanoid.MaxHealth then
			C.Value = Dmg
		else
			C.Value = Humanoid.MaxHealth
		end
	end
end

function Module:IsAccessory(Part)
	if Part.Parent:IsA("Accessory") or Part.Parent:IsA("Hat") or Part.Parent:IsA("Accoutrement") then return true end
	return false
end

function Module:IsTool(Part)
	if Part.Parent:IsA("Tool") then return true end
	return false
end

function Module:OnHit(Part)
	if Part and Part.Parent:FindFirstChild("Humanoid") and Part.Parent:FindFirstChild("Head") then
		local Humanoid = Part.Parent:FindFirstChild("Humanoid")
		if Humanoid.Parent ~= Module.Tool.Parent then
			if Part.Name ~= "Head" then
				print("a")
				Humanoid:TakeDamage(Module.Settings.Damage)
				print("b")
				Module:TagHumanoid(game.Players:GetPlayerFromCharacter(Module.Tool.Parent),Humanoid,Module.Settings.Damage)
				print("c")
			elseif Part.Name == "Head" then
				print("d")
				Humanoid:TakeDamage(Module.Settings.HeadDamage)
				print("e")
				Module:TagHumanoid(game.Players:GetPlayerFromCharacter(Module.Tool.Parent),Humanoid,Module.Settings.HeadDamage)
			elseif Part.Name == "Shaggy2" or Part.Name == "Handle" then
				print("12e1")
				Part.Parent = Part.Parent.Parent
				print("f")
				print("g")
				Humanoid:TakeDamage(Module.Settings.HeadDamage)
				print("h")
				Module:TagHumanoid(game.Players:GetPlayerFromCharacter(Module.Tool.Parent),Humanoid,Module.Settings.HeadDamage)
				print("i")
			end
		end
	end
end

function Module:Unequip()
	Module.ArmsDown = false
end

function Module:ToggleArmsDown(Torso)
	for _,v in pairs(Torso:GetChildren()) do
		if v:IsA("Weld") then
			if v.Part1.Name == "Right Arm" then
				if Module.ArmsDown then
					v.C1 = CFrame.new(-1, -0.2, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
				else
					v.C1 = CFrame.new(-.8, -0.5, -0.3) * CFrame.fromEulerAnglesXYZ(math.rad(-50), math.rad(-60), 0)
				end
			elseif v.Part1.Name == "Left Arm" then
				if Module.ArmsDown then
					v.C1 = CFrame.new(-0.4, 0.9, 0.8) * CFrame.fromEulerAnglesXYZ(math.rad(300), 0, math.rad(-90))
				else
					v.C1 = CFrame.new(0.9,0,.5) * CFrame.fromEulerAnglesXYZ(math.rad(315), 0, math.rad(-30))
				end
			end
		end
	end
	Module.ArmsDown = not Module.ArmsDown
end

function Module:CreateGui(Player)
	if not Player.PlayerGui:FindFirstChild(Module.ReserveGUI.Name) then
		Module.GUI = Module.ReserveGUI:Clone()
		Module.GUI.Parent = Player.PlayerGui
		while Module.GUI ~= nil do
			wait()
			Module.GUI.Frame.Clips.Text = "Clips: "..Module.CurrentClips
			Module.GUI.Frame.Ammo.Text = "Ammo: "..Module.CurrentAmmo.."/"..Module.Settings.AmmoPerClip
			if Module.CurrentAmmo == 0 then
				Module.GUI.Frame.Ammo.TextColor3 = Color3.new(1,170/255,170/255)
			else
				Module.GUI.Frame.Ammo.TextColor3 = Color3.new(1,1,1)
			end
			if Module.CurrentClips == 0 then
				Module.GUI.Frame.Clips.TextColor3 = Color3.new(1,170/255,170/255)
			else
				Module.GUI.Frame.Clips.TextColor3 = Color3.new(1,1,1)
			end
		end
	end
end

function Module:RemoveGui(Player)
	if Player.PlayerGui:FindFirstChild(Module.ReserveGUI.Name) then
		Module.GUI = nil
		Player.PlayerGui:FindFirstChild(Module.ReserveGUI.Name):Destroy()
	end
end

function Module:Reload()
	if Module.CurrentClips >= 1 then
		Module.Handle.Reload:Play()
		wait(Module.Settings.Reload)
		Module.CurrentClips = Module.CurrentClips - 1
		Module.CurrentAmmo = Module.Settings.AmmoPerClip
	end
end

function Module:ToggleLight()
	local SpotLight = Module.Form.MainLight.SpotLight
	Module.Handle.Click:Play()
	SpotLight.Enabled = not SpotLight.Enabled
end

function Module:Fire(Position)
	Module.CurrentAmmo = Module.CurrentAmmo - 1
	local Distance = (Module.Form.ShotPart.Position - Position).magnitude
	local Offset = Module.Settings.Offset
	local Direction = CFrame.new(Module.Form.ShotPart.Position, Position)
	Direction = Direction * CFrame.Angles((math.random(-Offset, Offset)/200),(math.random(-Offset, Offset)/200),(math.random(-Offset,Offset)/200))
	Direction = Direction + Direction.lookVector * -Distance
	Direction = Direction.lookVector
	local HitPart,Pos = workspace:FindPartOnRay(Ray.new(Module.Form.ShotPart.Position,Direction*Module.Settings.MaxRange))
	Module:OnHit(HitPart)
	print(HitPart)
	Module.Handle.Fire:Play()
	local Shot = Instance.new("Part", workspace) 
	Shot.CanCollide = false
	Shot.FormFactor = "Custom" 
	Shot.Size = Vector3.new(0.2,0.2,0.2) 
	Shot.Anchored = true
	Shot.Material = "Neon"
	Shot.CFrame = CFrame.new(Module.Form.ShotPart.Position, Pos)
	Shot.Transparency = 0.5
	local ShotColor = Module.Form.MainLight.BrickColor.Name
	Shot.BrickColor = BrickColor.new(ShotColor)
	local Mesh = Instance.new("BlockMesh", Shot) 
	Mesh.Scale = Vector3.new(0.1, 0.1, ((Module.Form.ShotPart.Position - Pos).magnitude)/0.2) 
	Mesh.Offset = Vector3.new(0,0,(Module.Form.ShotPart.Position - Pos).magnitude/-2) 
	game.Debris:AddItem(Shot, 0.06)
	Module.Form.ShotPart.Voltage.Enabled = true
	wait(0.15)
	Module.Form.ShotPart.Voltage.Enabled = false
	wait(Module.Settings.Recoil - 0.15)
end

return Module

I tried to edit this gun script, but for some reason when I tried to add a check to see if the accessory is detected in the onhit function, it doesn’t actually print or do damage to the humanoid.

Try adding prints in to verify the logic path is a you expect.
For example in Module:OnHit add print(“Humanoid.Parent not equal to Module.Tool.Parent”) as an else to the if so if the compare fails you know it has.

I added the prints, and I noticed that it isn’t detecting the accessory. But it is detecting the handle of the accessory. So when I add an elseif statement to run when the Part.Name == “Handle”, it doesn’t even print for some weird reason.

I am assuming the prints are in the script requiring the module and that the accessory is added via script so after the add can you verify the accessory is actually there?

Well, there isn’t an accessory that is made from a script.

So what do you get for the print of the HitPart?

I got the print of the hitpart in the fire function.

Sorry I should have been more specific.
What do you see in the console from the prints in the test run and do any of them show the accessory?

Yes, it detects the accessory and the handle.

OK. So in the OnHit where the part is the accessory it should as it is not the “Head” print out “a” and do the take damage and then print out “b” etc.