What the heck is happening with my HitBox?

  1. What do you want to achieve?

Just making my axe, anything was going well until something unexpected happens

  1. What is the issue?

As you can see, I hit a dummy with my axe. And I saw something is not right. When I walk far from the dummy. The axe didn’t hit the dummy and still deal damage? Wait. What the heck?

  1. What solutions have you tried so far?

I have no idea.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Melee = script.Parent
local Handle = Melee.Attacher
local HitPart = Melee.MeshPart

local IsKilling = false
local WhileKilling = false

-- Ignored variables --
local RandomAnims
local RandomHitSound 
local SwingSound
local HitSound
local PlayHitSound
local PlayRandomAnims
local Idle
local Humanoid
-- Ignored variables --

local Settings = script.Parent:WaitForChild("Settings")

local CoolDown = Settings:WaitForChild("Cooldown")
local Second_CoolDown = Settings:WaitForChild("Second_Cooldown")
local WalkSpeed = Settings:WaitForChild("Speed")
local Damage = Settings:WaitForChild("Damage")

local function OnEquipping()
	local Char = script.Parent.Parent
	Humanoid = Char:WaitForChild("Humanoid")
	Humanoid.WalkSpeed = WalkSpeed.Value
	Idle = Humanoid:LoadAnimation(script.Idle_Anim.Idle)
	Idle:Play()
	
	RandomAnims = {
		Humanoid:LoadAnimation(script.Swing_Anim.Swing1)
	}
	
	HitSound = {
		Handle:WaitForChild("Hit")
	}
end

local function OnAttack()
	if not IsKilling then
		IsKilling = true
		
		PlayRandomAnims = RandomAnims[math.random(#RandomAnims)]
		SwingSound = Handle:WaitForChild("Swing"):Play()
		PlayRandomAnims:Play()
		Idle:Stop()
		
			HitPart.Touched:Connect(function(hit)
			
			if IsKilling then
				if hit.Parent:FindFirstChild("Humanoid") then
					if not WhileKilling then
						WhileKilling = true
						PlayRandomAnims:GetMarkerReachedSignal("HitMarker"):Connect(function()	
								hit.Parent.Humanoid:TakeDamage(Damage.Value)
								HitSound[math.random(#HitSound)]:Play()
						end)	
						wait(Second_CoolDown.Value)
						WhileKilling = false
					end
				end
			elseif not IsKilling then
				return
			end
		end)
	
		wait(CoolDown.Value)
		
		Idle:Play()
		IsKilling = false
	end
end

local function UnEquipping()
	Humanoid.WalkSpeed = 16
	IsKilling = false
	WhileKilling = false
	Idle:Stop()
end

Melee.Activated:Connect(OnAttack)
Melee.Equipped:Connect(OnEquipping)
Melee.Unequipped:Connect(UnEquipping)

And this is how the loadout looks like :

image

Side note : MeshPart is a “HitBox”

1 Like

It’s a little funny, but it’s 100% not your hitbox lol

You’re not cleaning up your connections. So every time you swing, you’re connecting another .Touched event. And with every .Touched event happening you’re connecting to GetMarkerReachedSignal.
So now each time you play that animation, it’ll do damage to that dummy. Even worse, each time your axe touches an instance, it’ll affect that other instance too.

To fix this, you have to disconnect your events like so:

local connection = HitPart.Touched:Connect(function(hit)
    -- code
end)
task.wait(3) -- wait 3 seconds
connection:Disconnect() -- disconnects the connection so it wont run again
2 Likes

Changed the code to this :

local Melee = script.Parent
local Handle = Melee.Attacher
local HitPart = Melee.MeshPart

local IsKilling = false
local WhileKilling = false

-- Ignored variables --
local RandomAnims
local RandomHitSound 
local SwingSound
local HitSound
local PlayHitSound
local PlayRandomAnims
local Idle
local Humanoid
-- Ignored variables --

local Settings = script.Parent:WaitForChild("Settings")

local CoolDown = Settings:WaitForChild("Cooldown")
local Second_CoolDown = Settings:WaitForChild("Second_Cooldown")
local WalkSpeed = Settings:WaitForChild("Speed")
local Damage = Settings:WaitForChild("Damage")

local function OnEquipping()
	local Char = script.Parent.Parent
	Humanoid = Char:WaitForChild("Humanoid")
	Humanoid.WalkSpeed = WalkSpeed.Value
	Idle = Humanoid:LoadAnimation(script.Idle_Anim.Idle)
	Idle:Play()
	
	RandomAnims = {
		Humanoid:LoadAnimation(script.Swing_Anim.Swing1)
	}
	
	HitSound = {
		Handle:WaitForChild("Hit")
	}
end

local function OnAttack()
	if not IsKilling then
		IsKilling = true
		
		PlayRandomAnims = RandomAnims[math.random(#RandomAnims)]
		SwingSound = Handle:WaitForChild("Swing"):Play()
		PlayRandomAnims:Play()
		Idle:Stop()
		
		local connection = HitPart.Touched:Connect(function(hit)
			
			if IsKilling then
				if hit.Parent:FindFirstChild("Humanoid") then
					if not WhileKilling then
						WhileKilling = true
						PlayRandomAnims:GetMarkerReachedSignal("HitMarker"):Connect(function()	
								hit.Parent.Humanoid:TakeDamage(Damage.Value)
								HitSound[math.random(#HitSound)]:Play()
						end)	
						wait(Second_CoolDown.Value)
						WhileKilling = false
					end
				end
			elseif not IsKilling then
				return
			end
		end)
	
		wait(CoolDown.Value)
		
		connection:Disconnect()
		Idle:Play()
		IsKilling = false
	end
end

local function UnEquipping()
	Humanoid.WalkSpeed = 16
	IsKilling = false
	WhileKilling = false
	Idle:Stop()
end

Melee.Activated:Connect(OnAttack)
Melee.Equipped:Connect(OnEquipping)
Melee.Unequipped:Connect(UnEquipping)

Results was same like below :

2 Likes

Please help me, I’m really running out of ideas.

1 Like

I suggest printing the name of the bodypart being hit to narrow down the diagnosis of your problem.

1 Like

Hey, it’s working. After wasting a several hours, I just found out and it’s very simple lmao :skull:
the code was like this

local connection = PlayRandomAnims:GetMarkerReachedSignal("HitMarker"):Connect(function()
-- goofy ahh ohio code
end)
task.wait(69)
WhileKilling = false
connection:Disconnect()

Now it doesn’t deal any damage… only it hits the dummy! THANKZZ!1!!

2 Likes

Pleas plea eapleas eplease use raycasthitbox instead of touched its much better

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.