Issue with my Sword Script and Animation doesn't play!

My scripting skill isn’t good and I use HowToRoblox’s Sword Script and modify it to the thing I want. But when I test it, it seem do be broken and the animation doesn’t play when I click.

local tool = script.Parent

local idleAnim = script:WaitForChild("Idle")
local idleAnimTrack
local swingAnim = script:WaitForChild("Swing")
local swingAnimTrack

local hitCharacters = {}
local debounce = false

tool.Equipped:Connect(function()

	local humanoid = script.Parent.Parent.Humanoid
	if not idleAnimTrack then idleAnimTrack = humanoid:LoadAnimation(idleAnim) end

	idleAnimTrack:Play()
end)
tool.Unequipped:Connect(function()

	if idleAnimTrack then idleAnimTrack:Stop() end
	if swingAnimTrack then swingAnimTrack:Stop() end

end)
tool.Activated:Connect(function()

	if debounce then return end
	debounce = true

	local humanoid = script.Parent.Parent.Humanoid
	if not swingAnimTrack then swingAnimTrack = humanoid:LoadAnimation(swingAnim) end

	swingAnimTrack:Play()

	wait(0.5)	

	wait(0.5)
	debounce = false
end)
tool.Blade.Touched:Connect(function(touch)

	local hitter = script.Parent.Parent
	local allyteam = {"Wizard","Medic"}
	local badteam = {"Barbarian"}

	if hitCharacters[touch.Parent] or not debounce then return end
	if touch.Parent:FindFirstChild("Humanoid") then
		if touch.Parent.Team.Name == allyteam and hitter.Team.Name == badteam then 

			if touch.Name == "Head" then
				touch.Parent.Humanoid:TakeDamage(10)

				hitCharacters[touch.Parent] = true
				wait(1)
				hitCharacters[touch.Parent] = nil		
			end
			
			if touch.Parent:FindFirstChild("Humanoid").Health == 0 then
				hitter.leaderstats.Kills.Value = hitter.leaderstats.Kills.Value + 1
			end
		end
	end
end)

I have search some Solution but they seem not helpful for me

1 Like