Problems with Raycast Hitbox V3

  1. What do you want to achieve?
    I was trying to make a simple heavy attack with the raycast module just to pratice since it’s my first time with it.

  2. What is the issue?
    Well testing with some friends I noticed that once you attack someone they kinda get bugged, in case you attack they would play the attack animation, active the raycast and damage if someone is near them but also they can be damaged by their own hitbox. Apparently once you hit someone by attacking you can activate their tool hitbox, it’s pretty weird to explain.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have no idea what could work to fix my problem and I can’t find anyone with the same problem on the Developer Hub.

This is my code, please forgive that it’s really messy and might be hard to read but first time using the module.

local tool = script.Parent.Parent
local Sword = tool.Sword
local previouscombo
local RaycastHitbox = require(tool.RaycastHitboxV2)
local debounce = false

game.ReplicatedStorage.Remotes.Sword.Heavy.OnServerEvent:connect(function(player, Action)
	local Character = player.Character
	local anim
	if Action == "Heavy" then
		if Character.Humanoid:FindFirstChild("Stun") or Character.Humanoid.Jump == true then return end
		local hit = Instance.new("ObjectValue", Character.Humanoid)
		hit.Name = "HeavyHitting"
		hit.Value = player
		game.Debris:AddItem(hit, 0.3)
		local Hitbox = RaycastHitbox:Initialize(tool, {Character})
		Hitbox:DebugMode(true)
		Sword.Trail.Enabled = true
		local Track1 = game.ReplicatedStorage.Assets.Sword.Animations.Heavy
		anim = Character.Humanoid:LoadAnimation(Track1)
		anim:Play()
		local Slash = Instance.new("Sound", Sword)
		Slash.SoundId = "rbxassetid://6096282630"
		Slash.Volume = 0.05
		Slash:Play()
		Character.Humanoid.JumpPower = 0
		
		local Connection = Hitbox.OnHit:Connect(function(hit, humanoid)
			for i, v in pairs(humanoid:GetChildren()) do
				if v.Name == "Stun" then
					if v.Value == player then
						return
					end
				end
			end

			if not hit:FindFirstChild("Block") and not hit.Parent:FindFirstChild("Parry") then
				local Stun = Instance.new("ObjectValue", humanoid)
				Stun.Name = "Stun"
				Stun.Value = player
				game.Debris:AddItem(Stun, 0.4)
				hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)

				local hittrack = game.ReplicatedStorage.Assets.Sword.Animations.GettingHit
				local hitanim = humanoid:LoadAnimation(hittrack)
				hitanim:Play()

				local bv = Instance.new("BodyVelocity", hit.Parent.HumanoidRootPart)
				bv.MaxForce = Vector3.new(25000, 0, 25000)
				bv.Velocity = hit.Parent.HumanoidRootPart.CFrame.LookVector * -15
				game.Debris:AddItem(bv, 0.15)

				local slice = Instance.new("Sound", hit.Parent.Torso)
				slice.SoundId = "rbxassetid://4988622242"
				slice.Volume = 0.05
				slice:Play()
				game.Debris:AddItem(slice, 0.3)

				spawn(function()
					local hiteffect = game.ReplicatedStorage.bleed:Clone()
					hiteffect.CFrame = hit.Parent.Torso.CFrame
					hiteffect.Parent = workspace
					hiteffect.Effect1.Rate = 30 + (150 - (1.5*humanoid.Health))
					hiteffect.Effect2.Rate = 30 + (150 - (1.5*humanoid.Health))
					hiteffect.Effect3.Rate = 30 + (150 - (1.5*humanoid.Health))
					wait(0.4 - humanoid.Health/500)
					hiteffect.Effect1.Enabled = false
					hiteffect.Effect2.Enabled = false
					hiteffect.Effect3.Enabled = false
					wait(0.75)
					hiteffect:Destroy()
				end)

			elseif hit:FindFirstChild("Block") and not hit.Parent:FindFirstChild("Parry") and debounce == false then
				hit.Block:Destroy()
				local Stun = Instance.new("ObjectValue", humanoid)
				Stun.Name = "Stun"
				Stun.Value = player
				game.Debris:AddItem(Stun, 0.4)
				hit.Parent:FindFirstChild("Humanoid"):TakeDamage(3)

				local ShakeEvent = game.ReplicatedStorage.Remotes.Shake.FireShake
				local Target = hit.Parent
				ShakeEvent:FireClient(player, Target, "SwordHeavy")
				local hittrack = game.ReplicatedStorage.Assets.Sword.Animations.GettingHit
				local hitanim = humanoid:LoadAnimation(hittrack)
				hitanim:Play()

				local bv = Instance.new("BodyVelocity", hit.Parent.HumanoidRootPart)
				bv.MaxForce = Vector3.new(25000, 0, 25000)
				bv.Velocity = hit.Parent.HumanoidRootPart.CFrame.LookVector * -15
				game.Debris:AddItem(bv, 0.15)

				local slice = Instance.new("Sound", hit.Parent.Torso)
				slice.SoundId = "rbxassetid://4988622242"
				slice.Volume = 0.05
				slice:Play()
				game.Debris:AddItem(slice, 0.3)

			elseif hit.Parent:FindFirstChild("Parry") and debounce == false then
				debounce = true
				local Stun = Instance.new("ObjectValue", Character.Humanoid)
				Stun.Name = "Stun"
				Stun.Value = player
				game.Debris:AddItem(Stun, 0.5)


				local effect2 = game.ReplicatedStorage.parry:Clone()
				effect2.Parent = workspace
				effect2.Position = Sword.Position
				game.Debris:AddItem(effect2, 1)

				spawn(function()
					wait(0.25)
					effect2.Attachment.Circle.Enabled = false
					effect2.Attachment.Spark.Enabled = false
				end)

				Sword.Clash.Enabled = true

				spawn(function()
					wait(0.2)
					Sword.Clash.Enabled = false
				end)


				local parrysounds = {293847733, 293847696, 293847647, 5989945551}
				local rand = math.random(#parrysounds)
				local choose = parrysounds[rand]

				local sound = Instance.new("Sound")
				sound.SoundId = "rbxassetid://" ..choose
				sound.Parent = Sword
				sound.Volume = 1
				sound:Play()
				game.Debris:AddItem(sound, 1)

				anim:Stop()
				local track4 = game.ReplicatedStorage.Assets.Sword.Animations.BackOff
				local anim4 = Character.Humanoid:LoadAnimation(track4)
				anim4:Play()
				Hitbox:HitStop()
			end
	    end)

		if Character.Humanoid:FindFirstChild("Stun") then 
			anim:Stop()
			hit:Destroy()
			Connection:Disconnect()
			Hitbox:HitStop()
			return
		else
			Hitbox:HitStart()
			wait(0.3)
			Sword.Trail.Enabled = false
			Connection:Disconnect()
			Hitbox:HitStop()
			debounce = false
		end
		
		wait(0.4)
		Character.Humanoid.JumpPower = 50
	end
end)

Any of you guys got some idea of what could be causing this? :thinking:

try

local Connection
Connection = ...