Sword won't deal damage

  1. What do you want to achieve?
    I want a sword that works with animation

  2. What is the issue?
    The animations that i made work perfectly fine but the sword isn’t dealing damage

  3. What solutions have you tried so far?
    I’ve looked into the Dev forum and tried different methods but neither of them worked

Here is my code

attack.OnServerEvent:Connect(function(plr)
	local char = plr.Character	
	local hum = char:WaitForChild("Humanoid") 
	local animator = hum:WaitForChild("Animator")
	local anim = Instance.new("Animation", plr)
	anim.AnimationId = "rbxassetid://10401972276"
	local animtrack = animator:LoadAnimation(anim)
	animtrack:Play()
	repeat wait() until animtrack.IsPlaying
	hitbox.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent:FindFirstChild("Humanoid").Health -= 50
		end
	end) 
1 Like

Try this:

hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 50

or

hit.Parent:FindFirstChild("Humanoid"):TakeDamage(50)

By the way, what is hitbox? I don’t see variable line

Didn’t work, and i have the hitbox variable i just didn’t included it in the post
And there’s no errors

Can you remove this for a second and then try to play your script again.

Still doesn’t work im confused there is no even an error :confused:

1 Like

try this

hitbox.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid") 

if humanoid then
humanoid.Health = humanoid.Health - 50

end
end)
1 Like

Still doesn’t work i have tried to add an event and its still not working

Slightly hacky solution, but what you could do is weld an invisible part into the sword mesh/model and then put this script in the part:

local sword = script.Parent

local function dealDamage(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid then
        humanoid.Health = humanoid.Health - 50 --or however many integers
    end
end)

sword.Touched:Connect(dealDamage)