How can I fix my hitboxes?

My issue: when I swing my swords and it detects that it hit me (the one swinging the swords) it damages all dummies at the same time.

here’s my LocalScript located in StarterCharacterScripts (Enabled and Disabled upon AnimationEvents):

local Hitbox1 = script.Parent["Right Arm"]:WaitForChild("Handle").Holder.Blade:WaitForChild("Hitbox1")
local Hitbox2 = script.Parent["Left Arm"]:WaitForChild("Handle2").Holder.Blade:WaitForChild("Hitbox2")

local HitHumanoid = game.ReplicatedStorage.HitHumanoid
local SelfHumanoidHit = game.ReplicatedStorage.SelfHumanoidHit
local SelfHumanoid = script.Parent.Humanoid

local Debris = game:GetService("Debris")

while true do
	task.wait(0.01)
	local Hitbox1Clone = Instance.new("Part", workspace)
	Hitbox1Clone.Name = "Hitbox1"
	Hitbox1Clone.Size = Vector3.new(1.025, 1.46, 5.43)
	Hitbox1Clone.Anchored = true
	Hitbox1Clone.Transparency = 0.5
	Hitbox1Clone.CanCollide = false
	Hitbox1Clone.Color = Color3.new(1, 0, 0)
	Hitbox1Clone.Massless = true
	Hitbox1Clone.CanTouch = true
	Hitbox1Clone.Position = Hitbox1.Position
	Hitbox1Clone.Orientation = Hitbox1.Orientation
	Debris:AddItem(Hitbox1Clone, 1)
	local Hitbox2Clone = Instance.new("Part", workspace)
	Hitbox2Clone.Name = "Hitbox2"
	Hitbox2Clone.Size = Vector3.new(1.025, 1.46, 5.43)
	Hitbox2Clone.Anchored = true
	Hitbox2Clone.Transparency = 0.5
	Hitbox2Clone.CanCollide = false
	Hitbox2Clone.Color = Color3.new(0, 0, 1)
	Hitbox2Clone.Massless = true
	Hitbox2Clone.CanTouch = true
	Hitbox2Clone.Position = Hitbox2.Position
	Hitbox2Clone.Orientation = Hitbox2.Orientation
	Debris:AddItem(Hitbox2Clone, 1)
			
	Hitbox1Clone.Touched:Connect(function(hit)
		local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
			if Humanoid then
			print("hit1 other humanoid!")
			HitHumanoid:FireServer()
				Hitbox2Clone.CanTouch = false
		end
	end)
	Hitbox2Clone.Touched:Connect(function(hit)
		local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		if Humanoid then
			print("hit2 other humanoid!")
			HitHumanoid:FireServer()
			Hitbox1Clone.CanTouch = false
		end
	end)
	--------------SELF HIT---------------
	Hitbox1Clone.Touched:Connect(function(hit)
		if hit.Parent == script.Parent.Humanoid then
			SelfHumanoidHit:FireServer()
			print("Hit Self")
		end
	end)
	Hitbox2Clone.Touched:Connect(function(hit)
		if hit.Parent == script.Parent.Humanoid then
			SelfHumanoidHit:FireServer()
			print("Hit Self")
		end
	end)
end

And the ServerScript inside the dummies:

local HitHumanoid = game.ReplicatedStorage.HitHumanoid
local SelfHumanoidHit = game.ReplicatedStorage.SelfHumanoidHit

HitHumanoid.OnServerEvent:Connect(function()
	script.Parent.Humanoid:TakeDamage(50)
end)

SelfHumanoidHit.OnServerEvent:Connect(function()
	script.Parent.Humanoid:TakeDamage(0)
end)

This all happens when the swing animations reach animation events DamageStart and DamageEnd. I’ve tried doing elseif hit.Parent == SelfHumanoid then but when I do this, it doesn’t do anything. Please help!

Video Example of dummies all dying:

1 Like

When you fire the event all the dummies receive the event. So I would make one script and transfer the target to damage. Ex:

:FireServer(hit.Parent)

This is highly exploitable though so add safety measures.

2 Likes

tysm for the reply! Ill try it out and lyk! And when u say make one script, wdym?

1 Like

Oh I thought you had the damage script under each dummy. If you already have one main script that’s good.

1 Like

I do have under each dummy. I’m just confused on how implement what you said into my scrtip(s) pls help

here’s the changes I made:

	Hitbox1Clone.Touched:Connect(function(hit)
			print("hit1 other humanoid!")
			HitHumanoid:FireServer(hit.Parent)
			Hitbox2Clone.CanTouch = false
	end)
	Hitbox2Clone.Touched:Connect(function(hit)
			print("hit2 other humanoid!")
			HitHumanoid:FireServer(hit.Parent)
			Hitbox1Clone.CanTouch = false
	end)

and the changes I made to the damage script inside each dummy:

local HitHumanoid = game.ReplicatedStorage.HitHumanoid

HitHumanoid.OnServerEvent:Connect(function()
	script.Parent.Humanoid:TakeDamage(1)
end)
1 Like

Sorry for the late response.

So hit.Parent gives the server who needs to be damaged. We’ll call this target

.OnServerEvent:Connect(function(target)
local humanoid = target:WaitForChild(“Humanoid”)
humanoid:TakeDamage()

So you would want one main script in server script service instead of a script being under each dummy.

(On mobile sorry)

1 Like