AnimationTrack.IsPlaying, Lightsaber system

You can write your topic however you want, but you need to answer these questions:
I’m trying to make when you swing the lightsaber does damage

It doesn’t do damage tho

local hit2 = true

local player = game.Players.LocalPlayer

local char = player.Character or player.CharacterAdded:Wait()

local h = char:WaitForChild("Humanoid")

local AnimationTrack = h:LoadAnimation(script.Parent.main.swing)

script.Parent.Light.Touched:Connect(function(hit)
	if AnimationTrack.IsPlaying then
		local humanoid = hit.Parent:FindFirstChildWhichIsA	("Humanoid")
	if humanoid then
		if hit2 then
			hit2 = false
			humanoid.Health = humanoid.Health-20
			wait(0.8)
			hit2 = true
		end
		
	end
	end
	
end)

If i remove the AnimationTrack.IsPlaying then it will do damage but I need to check if the animation is playing then do damage

Are there any errors? If not maybe try putting print statements to see where the script is working or not.

I see many problems, such as you are handling server sided things inside the client. Try changing the health inside of a server script via remote events.

new code:

local hit2 = true

local player = game.Players.LocalPlayer

local char = player.Character or player.CharacterAdded:Wait()

local h = char:WaitForChild("Humanoid")

local AnimationTrack = h.Animator:LoadAnimation(script.Parent.main.swing)

script.Parent.Light.Touched:Connect(function(hit)
	if AnimationTrack.IsPlaying then
		local humanoid = hit.Parent:FindFirstChildWhichIsA	("Humanoid")
	if humanoid then
		if hit2 then
			hit2 = false
			--humanoid.Health = humanoid.Health-20
			wait(0.8)
			hit2 = true
		end
		
	end
	end
	
end)