Why does this sword damage me and not the other person?

Server:

local tool = script.Parent

tool.TakeDamage.OnServerEvent:Connect(function(plr,hum,damage)
	hum:TakeDamage(damage)
	if hum.Health == 0 then
		plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value + 1
	end
end)

Client:

local tool = script.Parent
local equipped = false
local activated = false
local db = false
local db2 = false
local animation
local hum

tool.Equipped:Connect(function()
	equipped = true
	local char = tool.Parent
	hum = char.Humanoid
end)

tool.Activated:Connect(function()
	if db == false then
		if equipped == true then
			if hum then
				animation = hum:LoadAnimation(script.Swing)
				animation:Play()
				activated = true
				animation.Stopped:Wait()
				activated = false
				db = true
				wait(1)
				db = false
			end
		end
	end
end)

tool.Handle.Touched:Connect(function(hit)
	if db == false then
		if activated == true then
			if hit.Parent.Humanoid then
				if hit.Parent.Humanoid ~= script.Parent.Parent.Humanoid then
					tool.TakeDamage:FireServer(hum,30)
					db = true
					wait(1)
					db = false
				end
			end
		end
	end
end)

tool.Unequipped:Connect(function()
	equipped = false
end)

In the end the sword damages ME instead of the enemy, can anyone help solve this?

You’re giving it your humanoid instead of the person that touched the sword’s humanoid, change

tool.TakeDamage:FireServer(hum,30)

To

tool.TakeDamage:FireServer(hit.Parent.Humanoid,30)
1 Like

That does work, but the kill stat does not go up when they die, can you help me understand what I did wrong there?

Try printing hum.Health as soon as you deal damage, maybe there’s no time for it to detect the change in health?

Try

if hum.Health <= 0 then
1 Like