--PROBABLY WOULDNT TOUCH ABOVE UNLESS YOU KNOW WHAT YOURE DOING


Tool.Equipped:Connect(function()

	CheckTables() --Check if Table with list of Sounds and Animations are made. If not, make them. Please do not delete this
	
	CanSwing = false

	if Settings.EquipAnim == true and Tool.Animations:findFirstChild("Equip") and Hum then --if equip animation true and requirements are met, do this
		local EA = Chr.Humanoid:LoadAnimation(Tool.Animations.Equip)
		EA:Play()
		if Tool.Sounds:findFirstChild("Equip") then
			Tool.Sounds.Equip:Play()
		end
		EA.Stopped:wait()
	elseif Settings.EquipAnim == true then --if equip is true but you're missing an animation, print that so we know
		print(Plr.Name .. "'s equip animation failed, requirement not met.")
	end
	
	CanSwing = true

end)

Tool.Activated:Connect(function()
	
	if CanSwing == true and Hum.Health > 0 then --if youre able to swing and you arent dead
	
		CanSwing = false
		CanDamage = true
		local Swing = PickThing("Swing")
		local Sound = PickThing("Sound")
		
		--go though swings if more than one
		local SA = Hum:LoadAnimation(Swing)
		SA:Play()
		Sound:Play()
		
		wait(Settings.Cooldown)
		
		CanDamage = false
		CanSwing = true
		
	end
	
end)

Tool.Unequipped:Connect(function()
	
	CanSwing = false
	CanDamage = false
	
end)

Settings.Hitbox.Touched:Connect(function(Hit)
	local Mod = Hit.Parent

	if CanDamage == true then
		while not Mod:FindFirstChild("Humanoid") and Mod.Parent ~= game do
			Mod = Mod.Parent
		end
		local Hum = Mod:FindFirstChild("Humanoid")

		if game.Players:findFirstChild(Hum.Parent.Name) then
		else
			if Settings.KillNPCs == true then
				-- Check if target is not already dead
				if Hum.Health > 0 then
					Hum:TakeDamage(Settings.Damage)
					CanDamage = false

					-- Check if target is now dead
					if Hum.Health <= 0 then
						-- Increment Plr.leaderstats.Kills.Value by 1
						Plr.leaderstats.Kills.Value = Plr.leaderstats.Kills.Value + 1
					end
				end
			else
				return
			end
		end
	end
end)
